Skip to content

Commit 07e914f

Browse files
committed
✅ add eslint-config-typescript tests
1 parent bee2cf3 commit 07e914f

File tree

6 files changed

+95
-247
lines changed

6 files changed

+95
-247
lines changed

eslint-config-typescript/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
},
2626
"peerDependencies": {
2727
"@dudeofawesome/eslint-config": "^1.0.0",
28-
"typescript": "^4.7.4"
28+
"typescript": "^5.0.0, <5.2.0"
29+
},
30+
"devDependencies": {
31+
"@types/eslint": "^8.44.2",
32+
"@types/node": "^20.6.3",
33+
"ts-node": "^10.9.1"
2934
}
3035
}

eslint-config-typescript/test/index.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {
66
testRuleFail,
77
} from '../../utils/testing/eslint';
88

9-
const linter = new ESLint({ cwd: __dirname });
9+
// const linter = new ESLint({ cwd: __dirname });
10+
const linter = new ESLint({
11+
cwd: __dirname,
12+
overrideConfigFile: '.eslintrc.yaml',
13+
});
1014

1115
describe('eslint-config-typescript', () => {
1216
defaultTestSet(linter);
@@ -15,16 +19,8 @@ describe('eslint-config-typescript', () => {
1519
it(`should parse typescript`, () =>
1620
testNoFail(linter, `((a: string): string[] => a.split(''))()\n`, true));
1721

18-
it(`should parse javascript`, () =>
19-
testNoFail(linter, `((a) => a.split(''))()\n`));
20-
2122
it(`should not give eslint error on use before define`, () =>
22-
testNoFail(
23-
linter,
24-
`Number(a);
25-
const a = 10;\n`,
26-
true,
27-
));
23+
testNoFail(linter, `Number(a);\nconst a = 10;\n`, true));
2824
});
2925

3026
describe('fails', () => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "@dudeofawesome/typescript-configs/node.json",
3+
"files": ["index.ts", "index.js"]
4+
}

eslint-config/test/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, it } from 'node:test';
22
import { ESLint } from 'eslint';
33
import {
44
defaultTestSet,
5+
filePath,
56
testNoFail,
67
testRuleFail,
78
} from '../../utils/testing/eslint';
@@ -21,7 +22,7 @@ describe('eslint-config', () => {
2122
it(`should not parse typescript`, () =>
2223
linter
2324
.lintText(`((a: string): string[] => a.split(''))()\n`, {
24-
filePath: 'input.ts',
25+
filePath: filePath(true),
2526
})
2627
.then((res) => {
2728
equal(res[0].messages[0].ruleId, null);
@@ -31,6 +32,12 @@ describe('eslint-config', () => {
3132
);
3233
}));
3334

35+
it(`should fail no-console`, async () => {
36+
const res = await linter.lintText(`console.log('foo');\n`);
37+
// this gets 2 errors due to `console` not being defined
38+
strictEqual(res[0].messages[0].ruleId, 'no-console');
39+
});
40+
3441
// TODO: test for shopify rule
3542

3643
// TODO: test for prettier rule

0 commit comments

Comments
 (0)