eslint-plugin-cursor
Version:
ESLint plugin to detect mojibake (garbled characters) in source code
42 lines (41 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const MOJIBAKE_PATTERN = /[\uFFFD\u{FFFD}\u{FE63}\u{FF1F}]/gu;
const rule = {
meta: {
type: 'problem',
docs: {
description: 'Detect mojibake (garbled characters) in source code',
category: 'Possible Problems',
recommended: true,
},
schema: [],
messages: {
mojibakeDetected: '文字化けが検出されました。文字コードを確認してください。',
},
},
create(context) {
return {
Program(node) {
const sourceCode = context.getSourceCode();
const text = sourceCode.text;
let match;
while ((match = MOJIBAKE_PATTERN.exec(text)) !== null) {
const pos = sourceCode.getLocFromIndex(match.index);
context.report({
node,
loc: {
start: pos,
end: {
line: pos.line,
column: pos.column + 1
}
},
messageId: 'mojibakeDetected',
});
}
},
};
},
};
exports.default = rule;