Make unicode file lint rule more strict
parent
ab6a1b97f4
commit
da16e8c6e0
|
@ -41,28 +41,35 @@ function hygiene(some, linting = true) {
|
||||||
const unicode = es.through(function (file) {
|
const unicode = es.through(function (file) {
|
||||||
const lines = file.contents.toString('utf8').split(/\r\n|\r|\n/);
|
const lines = file.contents.toString('utf8').split(/\r\n|\r|\n/);
|
||||||
file.__lines = lines;
|
file.__lines = lines;
|
||||||
const skipAll = lines.some(line => /allow-any-unicode-file/.test(line));
|
const allowInComments = lines.some(line => /allow-any-unicode-comment-file/.test(line));
|
||||||
if (!skipAll) {
|
let skipNext = false;
|
||||||
let skipNext = false;
|
lines.forEach((line, i) => {
|
||||||
lines.forEach((line, i) => {
|
if (/allow-any-unicode-next-line/.test(line)) {
|
||||||
if (/allow-any-unicode-next-line/.test(line)) {
|
skipNext = true;
|
||||||
skipNext = true;
|
return;
|
||||||
return;
|
}
|
||||||
|
if (skipNext) {
|
||||||
|
skipNext = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If unicode is allowed in comments, trim the comment from the line
|
||||||
|
if (allowInComments) {
|
||||||
|
if (line.match(/\s+(\*)/)) { // Naive multi-line comment check
|
||||||
|
line = '';
|
||||||
|
} else {
|
||||||
|
const index = line.indexOf('\/\/');
|
||||||
|
line = index === -1 ? line : line.substring(0, index);
|
||||||
}
|
}
|
||||||
if (skipNext) {
|
}
|
||||||
skipNext = false;
|
// Please do not add symbols that resemble ASCII letters!
|
||||||
return;
|
const m = /([^\t\n\r\x20-\x7E⊃⊇✔︎✓🎯⚠️🛑🔴🚗🚙🚕🎉✨❗⇧⌥⌘×÷¦⋯…↑↓→→←↔⟷·•●◆▼⟪⟫┌└├⏎↩√φ]+)/g.exec(line);
|
||||||
}
|
if (m) {
|
||||||
// Please do not add symbols that resemble ASCII letters!
|
console.error(
|
||||||
const m = /([^\t\n\r\x20-\x7E⊃⊇✔︎✓🎯⚠️🛑🔴🚗🚙🚕🎉✨❗⇧⌥⌘×÷¦⋯…↑↓→→←↔⟷·•●◆▼⟪⟫┌└├⏎↩√φ]+)/g.exec(line);
|
file.relative + `(${i + 1},${m.index + 1}): Unexpected unicode character: "${m[0]}" (charCode: ${m[0].charCodeAt(0)}). To suppress, use // allow-any-unicode-next-line`
|
||||||
if (m) {
|
);
|
||||||
console.error(
|
errorCount++;
|
||||||
file.relative + `(${i + 1},${m.index + 1}): Unexpected unicode character: "${m[0]}" (charCode: ${m[0].charCodeAt(0)}). To suppress, use // allow-any-unicode-next-line`
|
}
|
||||||
);
|
});
|
||||||
errorCount++;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
this.emit('data', file);
|
this.emit('data', file);
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// allow-any-unicode-file
|
// allow-any-unicode-comment-file
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets alternative Korean characters for the character code. This will return the ascii
|
* Gets alternative Korean characters for the character code. This will return the ascii
|
||||||
|
|
Loading…
Reference in New Issue