📄 jslint.js
字号:
}
if (xmode !== 'styleproperty' && s.substr(0, 1).isAlpha()) {
warningAt("Missing space after '{a}'.",
line, character, t);
}
if (c === '0') {
d = t.substr(1, 1);
if (d.isDigit()) {
if (token.id !== '.' && xmode !== 'styleproperty') {
warningAt("Don't use extra leading zeros '{a}'.",
line, character, t);
}
} else if (jsonmode && (d === 'x' || d === 'X')) {
warningAt("Avoid 0x-. '{a}'.",
line, character, t);
}
}
if (t.substr(t.length - 1) === '.') {
warningAt(
"A trailing decimal point can be confused with a dot '{a}'.",
line, character, t);
}
return it('(number)', t);
}
switch (t) {
// string
case '"':
case "'":
return string(t);
// // comment
case '//':
if (src || (xmode && xmode !== 'script')) {
warningAt("Unexpected comment.", line, character);
} else if (xmode === 'script' && /<\s*\//i.test(s)) {
warningAt("Unexpected <\/ in comment.", line, character);
} else if ((option.safe || xmode === 'script') && ax.test(s)) {
warningAt("Dangerous comment.", line, character);
}
s = '';
token.comment = true;
break;
// /* comment
case '/*':
if (src || (xmode && xmode !== 'script' && xmode !== 'style' && xmode !== 'styleproperty')) {
warningAt("Unexpected comment.", line, character);
}
if (option.safe && ax.test(s)) {
warningAt("ADsafe comment violation.", line, character);
}
for (;;) {
i = s.search(lx);
if (i >= 0) {
break;
}
if (!nextLine()) {
errorAt("Unclosed comment.", line, character);
} else {
if (option.safe && ax.test(s)) {
warningAt("ADsafe comment violation.", line, character);
}
}
}
character += i + 2;
if (s.substr(i, 1) === '/') {
errorAt("Nested comment.", line, character);
}
s = s.substr(i + 2);
token.comment = true;
break;
// /*global /*extern /*members /*jslint */
case '/*global':
case '/*extern':
case '/*members':
case '/*member':
case '/*jslint':
case '*/':
return {
value: t,
type: 'special',
line: line,
character: character,
from: from
};
case '':
break;
// /
case '/':
if (prereg) {
depth = 0;
captures = 0;
l = 0;
for (;;) {
b = true;
c = s.charAt(l);
l += 1;
switch (c) {
case '':
errorAt("Unclosed regular expression.", line, from);
return;
case '/':
if (depth > 0) {
warningAt("Unescaped '{a}'.", line, from + l, '/');
}
c = s.substr(0, l - 1);
q = {
g: true,
i: true,
m: true
};
while (q[s.charAt(l)] === true) {
q[s.charAt(l)] = false;
l += 1;
}
character += l;
s = s.substr(l);
return it('(regexp)', c);
case '\\':
c = s.charAt(l);
if (c < ' ') {
warningAt("Unexpected control character in regular expression.", line, from + l);
} else if (c === '<') {
warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
}
l += 1;
break;
case '(':
depth += 1;
b = false;
if (s.charAt(l) === '?') {
l += 1;
switch (s.charAt(l)) {
case ':':
case '=':
case '!':
l += 1;
break;
default:
warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, ':', s.charAt(l));
}
} else {
captures += 1;
}
break;
case ')':
if (depth === 0) {
warningAt("Unescaped '{a}'.", line, from + l, ')');
} else {
depth -= 1;
}
break;
case ' ':
q = 1;
while (s.charAt(l) === ' ') {
l += 1;
q += 1;
}
if (q > 1) {
warningAt("Spaces are hard to count. Use {{a}}.", line, from + l, q);
}
break;
case '[':
if (s.charAt(l) === '^') {
l += 1;
}
q = false;
klass: do {
c = s.charAt(l);
l += 1;
switch (c) {
case '[':
case '^':
warningAt("Unescaped '{a}'.", line, from + l, c);
q = true;
break;
case '-':
if (q) {
q = false;
} else {
warningAt("Unescaped '{a}'.", line, from + l, '-');
q = true;
}
break;
case ']':
if (!q) {
warningAt("Unescaped '{a}'.", line, from + l - 1, '-');
}
break klass;
case '\\':
c = s.charAt(l);
if (c < ' ') {
warningAt("Unexpected control character in regular expression.", line, from + l);
} else if (c === '<') {
warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
}
l += 1;
q = true;
break;
case '/':
warningAt("Unescaped '{a}'.", line, from + l - 1, '/');
q = true;
break;
case '<':
if (xmode === 'script') {
c = s.charAt(l);
if (c === '!' || c === '/') {
warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c);
}
}
q = true;
break;
default:
q = true;
}
} while (c);
break;
case '.':
if (option.regexp) {
warningAt("Unexpected '{a}'.", line, from + l, c);
}
break;
case ']':
case '?':
case '{':
case '}':
case '+':
case '*':
warningAt("Unescaped '{a}'.", line, from + l, c);
break;
case '<':
if (xmode === 'script') {
c = s.charAt(l);
if (c === '!' || c === '/') {
warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c);
}
}
}
if (b) {
switch (s.charAt(l)) {
case '?':
case '+':
case '*':
l += 1;
if (s.charAt(l) === '?') {
l += 1;
}
break;
case '{':
l += 1;
c = s.charAt(l);
if (c < '0' || c > '9') {
warningAt("Expected a number and instead saw '{a}'.", line, from + l, c);
}
l += 1;
low = +c;
for (;;) {
c = s.charAt(l);
if (c < '0' || c > '9') {
break;
}
l += 1;
low = +c + (low * 10);
}
high = low;
if (c === ',') {
l += 1;
high = Infinity;
c = s.charAt(l);
if (c >= '0' && c <= '9') {
l += 1;
high = +c;
for (;;) {
c = s.charAt(l);
if (c < '0' || c > '9') {
break;
}
l += 1;
high = +c + (high * 10);
}
}
}
if (s.charAt(l) !== '}') {
warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, '}', c);
} else {
l += 1;
}
if (s.charAt(l) === '?') {
l += 1;
}
if (low > high) {
warningAt("'{a}' should not be greater than '{b}'.", line, from + l, low, high);
}
}
}
}
c = s.substr(0, l - 1);
character += l;
s = s.substr(l);
return it('(regexp)', c);
}
return it('(punctuator)', t);
// punctuator
case
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -