Skip to content

Commit d1552f4

Browse files
multibyte test case
1 parent 6c0838f commit d1552f4

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

packages/code-analyzer-eslint-engine/test/engine.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,30 @@ describe('Tests for fixes and suggestions in runRules', () => {
11581158
expect(violation.fixes![0].location.file).toEqual(fixableFile);
11591159
}
11601160
});
1161+
1162+
it('Fix locations are correct for files with multi-byte characters', async () => {
1163+
const multibyteFile: string = path.join(workspaceWithFixableViolations, 'fixable_multibyte.js');
1164+
const engine: Engine = await createEngineFromPlugin(DEFAULT_CONFIG_FOR_TESTING);
1165+
const runOptions: RunOptions = {
1166+
...createRunOptions(new Workspace('id', [workspaceWithFixableViolations], [multibyteFile])),
1167+
includeFixes: true
1168+
};
1169+
const results: EngineRunResults = await engine.runRules(['prefer-const'], runOptions);
1170+
1171+
expect(results.violations.length).toBeGreaterThanOrEqual(1);
1172+
const violationWithFix = results.violations.find(v => v.fixes && v.fixes.length > 0);
1173+
expect(violationWithFix).toBeDefined();
1174+
1175+
const fix = violationWithFix!.fixes![0];
1176+
// Fix should target line 1 (let greeting) and replace with const
1177+
expect(fix.location.file).toEqual(multibyteFile);
1178+
expect(fix.location.startLine).toEqual(1);
1179+
expect(fix.fixedCode).toContain('const');
1180+
// Verify the line/column values are valid positive integers
1181+
expect(fix.location.startColumn).toBeGreaterThanOrEqual(1);
1182+
expect(fix.location.endLine).toBeGreaterThanOrEqual(1);
1183+
expect(fix.location.endColumn).toBeGreaterThanOrEqual(1);
1184+
});
11611185
});
11621186

11631187
function loadRuleDescriptions(fileNameFromTestDataFolder: string): RuleDescription[] {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let greeting = "こんにちは";
2+
console.log(greeting);
3+
let emoji = "Hello 🌍 World";
4+
console.log(emoji);

0 commit comments

Comments
 (0)