Skip to content

Commit 3777b77

Browse files
uniqueiniquityJamesHenry
authored andcommitted
feat(typescript-estree)!: throw error on file not in project when project set (#760)
BREAKING CHANGE: by default we will now throw when a file is not in the `project` provided
1 parent 4496288 commit 3777b77

File tree

24 files changed

+173
-50
lines changed

24 files changed

+173
-50
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
**/tests/fixtures/**/*
2+
**/tests/fixture-project/**/*
23
**/dist
34
**/coverage
45
**/shared-fixtures
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var foo = true;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw 'should be ok because rule is not loaded';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw 'err'; // no-string-throw
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var foo = true // semicolon
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var foo = true; // fail
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

packages/eslint-plugin-tslint/tests/index.spec.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const ruleTester = new TSESLint.RuleTester({
1212
* Project is needed to generate the parserServices
1313
* within @typescript-eslint/parser
1414
*/
15-
project: './tests/tsconfig.json',
15+
project: './tests/fixture-project/tsconfig.json',
1616
},
1717
parser: require.resolve('@typescript-eslint/parser'),
1818
});
@@ -47,6 +47,7 @@ ruleTester.run('tslint/config', rule, {
4747
{
4848
code: 'var foo = true;',
4949
options: tslintRulesConfig,
50+
filename: './tests/fixture-project/1.ts',
5051
},
5152
{
5253
filename: './tests/test-project/file-spec.ts',
@@ -62,13 +63,15 @@ ruleTester.run('tslint/config', rule, {
6263
{
6364
code: 'throw "should be ok because rule is not loaded";',
6465
options: tslintRulesConfig,
66+
filename: './tests/fixture-project/2.ts',
6567
},
6668
],
6769

6870
invalid: [
6971
{
7072
options: [{ lintFile: './tests/test-project/tslint.json' }],
7173
code: 'throw "err" // no-string-throw',
74+
filename: './tests/fixture-project/3.ts',
7275
errors: [
7376
{
7477
messageId: 'failure',
@@ -84,6 +87,7 @@ ruleTester.run('tslint/config', rule, {
8487
code: 'var foo = true // semicolon',
8588
options: tslintRulesConfig,
8689
output: 'var foo = true // semicolon',
90+
filename: './tests/fixture-project/4.ts',
8791
errors: [
8892
{
8993
messageId: 'failure',
@@ -100,6 +104,7 @@ ruleTester.run('tslint/config', rule, {
100104
code: 'var foo = true // fail',
101105
options: tslintRulesDirectoryConfig,
102106
output: 'var foo = true // fail',
107+
filename: './tests/fixture-project/5.ts',
103108
errors: [
104109
{
105110
messageId: 'failure',
@@ -174,26 +179,30 @@ describe('tslint/error', () => {
174179
});
175180
});
176181

177-
it('should not crash if there is no tslint rules specified', () => {
182+
it('should not crash if there are no tslint rules specified', () => {
178183
const linter = new TSESLint.Linter();
179184
jest.spyOn(console, 'warn').mockImplementation();
180185
linter.defineRule('tslint/config', rule);
181186
linter.defineParser('@typescript-eslint/parser', parser);
182187
expect(() =>
183-
linter.verify('foo;', {
184-
parserOptions: {
185-
project: `${__dirname}/test-project/tsconfig.json`,
186-
},
187-
rules: {
188-
'tslint/config': [2, {}],
188+
linter.verify(
189+
'foo;',
190+
{
191+
parserOptions: {
192+
project: `${__dirname}/test-project/tsconfig.json`,
193+
},
194+
rules: {
195+
'tslint/config': [2, {}],
196+
},
197+
parser: '@typescript-eslint/parser',
189198
},
190-
parser: '@typescript-eslint/parser',
191-
}),
199+
`${__dirname}/test-project/extra.ts`,
200+
),
192201
).not.toThrow();
193202

194203
expect(console.warn).toHaveBeenCalledWith(
195204
expect.stringContaining(
196-
'Tried to lint <input> but found no valid, enabled rules for this file type and file path in the resolved configuration.',
205+
`Tried to lint ${__dirname}/test-project/extra.ts but found no valid, enabled rules for this file type and file path in the resolved configuration.`,
197206
),
198207
);
199208
jest.resetAllMocks();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo;

0 commit comments

Comments
 (0)