Skip to content

Commit 70235ac

Browse files
author
stefanoviv
committed
Add type aware lint fail reproduction
1 parent 90d1fc4 commit 70235ac

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const fortyTwoFromGTS = '42';
2+
3+
<template>
4+
{{fortyTwoFromGTS}}
5+
</template>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const fortyTwoFromTS = '42';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { fortyTwoFromGTS } from './bar.gts';
2+
import { fortyTwoFromTS } from './baz.ts';
3+
4+
export const fortyTwoLocal = '42';
5+
6+
const helloWorldFromGTS = fortyTwoFromGTS[0] === '4' ? 'hello' : 'world';
7+
const helloWorldFromTS = fortyTwoFromTS[0] === '4' ? 'hello' : 'world';
8+
const helloWorld = fortyTwoLocal[0] === '4' ? 'hello' : 'world';
9+
10+
<template>
11+
{{helloWorld}}
12+
{{helloWorldFromTS}}
13+
{{helloWorldFromGTS}}
14+
</template>

tests/lib/rules-preprocessor/gjs-gts-parser-test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,4 +761,76 @@ describe('multiple tokens in same file', () => {
761761
expect(resultErrors[2].message).toBe("'bar' is not defined.");
762762
expect(resultErrors[2].line).toBe(17);
763763
});
764+
765+
it('lints while being type aware', async () => {
766+
const eslint = new ESLint({
767+
ignore: false,
768+
useEslintrc: false,
769+
plugins: { ember: plugin },
770+
overrideConfig: {
771+
root: true,
772+
env: {
773+
browser: true,
774+
},
775+
plugins: ['ember'],
776+
extends: ['plugin:ember/recommended'],
777+
overrides: [
778+
{
779+
files: ['**/*.gts'],
780+
parser: 'eslint-plugin-ember/gjs-gts-parser',
781+
parserOptions: {
782+
project: './tsconfig.eslint.json',
783+
tsconfigRootDir: __dirname,
784+
extraFileExtensions: ['.gts'],
785+
},
786+
extends: [
787+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
788+
'plugin:ember/recommended',
789+
],
790+
rules: {
791+
'no-trailing-spaces': 'error',
792+
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
793+
},
794+
},
795+
{
796+
files: ['**/*.ts'],
797+
parser: '@typescript-eslint/parser',
798+
parserOptions: {
799+
project: './tsconfig.eslint.json',
800+
tsconfigRootDir: __dirname,
801+
extraFileExtensions: ['.gts'],
802+
},
803+
extends: [
804+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
805+
'plugin:ember/recommended',
806+
],
807+
rules: {
808+
'no-trailing-spaces': 'error',
809+
},
810+
},
811+
],
812+
rules: {
813+
quotes: ['error', 'single'],
814+
semi: ['error', 'always'],
815+
'object-curly-spacing': ['error', 'always'],
816+
'lines-between-class-members': 'error',
817+
'no-undef': 'error',
818+
'no-unused-vars': 'error',
819+
'ember/no-get': 'off',
820+
'ember/no-array-prototype-extensions': 'error',
821+
'ember/no-unused-services': 'error',
822+
},
823+
},
824+
});
825+
826+
const results = await eslint.lintFiles(['**/*.gts', '**/*.ts']);
827+
828+
const resultErrors = results.flatMap((result) => result.messages);
829+
830+
expect(resultErrors[0].message).toBe("Use 'String#startsWith' method instead."); // Actual result is "Unsafe member access [0] on an `any` value."
831+
832+
expect(resultErrors[1].message).toBe("Use 'String#startsWith' method instead.");
833+
834+
expect(resultErrors[2].message).toBe("Use 'String#startsWith' method instead.");
835+
});
764836
});

tests/lib/rules-preprocessor/tsconfig.eslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"strictNullChecks": true
66
},
77
"include": [
8-
"*"
8+
"**/*"
99
]
1010
}

0 commit comments

Comments
 (0)