Skip to content

Commit 84831ca

Browse files
committed
fix: support custom parsers in configuration
1 parent bdea4b1 commit 84831ca

File tree

6 files changed

+135
-1
lines changed

6 files changed

+135
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@types/estree": "^0.0.50",
4141
"@types/jest": "^27.0.0",
4242
"@types/node": "^16.6.0",
43+
"@typescript-eslint/parser": "^5.11.0",
4344
"eslint": "^8.0.0",
4445
"jest": "^27.0.0",
4546
"prettier": "^2.4.0",

src/ruleSnapshotTester.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ export function runLintFixtureTests({
100100
tests.forEach((entry) => {
101101
test(entry.testName, () => {
102102
const linter = new Linter({})
103+
if (eslintConfig.parser) {
104+
try {
105+
const parserModule = require(eslintConfig.parser)
106+
linter.defineParser(eslintConfig.parser, parserModule)
107+
} catch (e) {
108+
console.error(`Failed to install configured parser "${eslintConfig.parser}"`)
109+
throw e
110+
}
111+
}
112+
103113
linter.defineRule(ruleName, rule)
104114
const lintConfig: Linter.Config = {
105115
...eslintConfig,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`should parse TypeScript 1`] = `
4+
"
5+
interface Test {
6+
thing(): void;
7+
}
8+
9+
const fooTest = 'foo';
10+
~~~~~~~ [1]
11+
12+
const testObj: Test = {
13+
thing() {}
14+
}
15+
16+
[1] variable name 'fooTest' should not include 'foo'."
17+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @test should parse TypeScript
3+
*/
4+
interface Test {
5+
thing(): void;
6+
}
7+
8+
const fooTest = 'foo';
9+
10+
const testObj: Test = {
11+
thing() {}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { runLintFixtureTests } from '../../ruleSnapshotTester'
2+
import { noFooAllowed } from '../rules/no-foo-allowed'
3+
4+
runLintFixtureTests({
5+
rule: noFooAllowed,
6+
ruleName: 'custom-parser',
7+
eslintConfig: {
8+
parser: '@typescript-eslint/parser',
9+
},
10+
})

yarn.lock

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,50 @@
16341634
dependencies:
16351635
"@types/yargs-parser" "*"
16361636

1637+
"@typescript-eslint/parser@^5.11.0":
1638+
version "5.11.0"
1639+
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.11.0.tgz#b4fcaf65513f9b34bdcbffdda055724a5efb7e04"
1640+
integrity sha512-x0DCjetHZYBRovJdr3U0zG9OOdNXUaFLJ82ehr1AlkArljJuwEsgnud+Q7umlGDFLFrs8tU8ybQDFocp/eX8mQ==
1641+
dependencies:
1642+
"@typescript-eslint/scope-manager" "5.11.0"
1643+
"@typescript-eslint/types" "5.11.0"
1644+
"@typescript-eslint/typescript-estree" "5.11.0"
1645+
debug "^4.3.2"
1646+
1647+
"@typescript-eslint/[email protected]":
1648+
version "5.11.0"
1649+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.11.0.tgz#f5aef83ff253f457ecbee5f46f762298f0101e4b"
1650+
integrity sha512-z+K4LlahDFVMww20t/0zcA7gq/NgOawaLuxgqGRVKS0PiZlCTIUtX0EJbC0BK1JtR4CelmkPK67zuCgpdlF4EA==
1651+
dependencies:
1652+
"@typescript-eslint/types" "5.11.0"
1653+
"@typescript-eslint/visitor-keys" "5.11.0"
1654+
1655+
"@typescript-eslint/[email protected]":
1656+
version "5.11.0"
1657+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.11.0.tgz#ba345818a2540fdf2755c804dc2158517ab61188"
1658+
integrity sha512-cxgBFGSRCoBEhvSVLkKw39+kMzUKHlJGVwwMbPcTZX3qEhuXhrjwaZXWMxVfxDgyMm+b5Q5b29Llo2yow8Y7xQ==
1659+
1660+
"@typescript-eslint/[email protected]":
1661+
version "5.11.0"
1662+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.11.0.tgz#53f9e09b88368191e52020af77c312a4777ffa43"
1663+
integrity sha512-yVH9hKIv3ZN3lw8m/Jy5I4oXO4ZBMqijcXCdA4mY8ull6TPTAoQnKKrcZ0HDXg7Bsl0Unwwx7jcXMuNZc0m4lg==
1664+
dependencies:
1665+
"@typescript-eslint/types" "5.11.0"
1666+
"@typescript-eslint/visitor-keys" "5.11.0"
1667+
debug "^4.3.2"
1668+
globby "^11.0.4"
1669+
is-glob "^4.0.3"
1670+
semver "^7.3.5"
1671+
tsutils "^3.21.0"
1672+
1673+
"@typescript-eslint/[email protected]":
1674+
version "5.11.0"
1675+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.11.0.tgz#888542381f1a2ac745b06d110c83c0b261487ebb"
1676+
integrity sha512-E8w/vJReMGuloGxJDkpPlGwhxocxOpSVgSvjiLO5IxZPmxZF30weOeJYyPSEACwM+X4NziYS9q+WkN/2DHYQwA==
1677+
dependencies:
1678+
"@typescript-eslint/types" "5.11.0"
1679+
eslint-visitor-keys "^3.0.0"
1680+
16371681
JSONStream@^1.0.4:
16381682
version "1.3.5"
16391683
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
@@ -2883,6 +2927,17 @@ fast-glob@^3.1.1:
28832927
merge2 "^1.3.0"
28842928
micromatch "^4.0.4"
28852929

2930+
fast-glob@^3.2.9:
2931+
version "3.2.11"
2932+
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
2933+
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
2934+
dependencies:
2935+
"@nodelib/fs.stat" "^2.0.2"
2936+
"@nodelib/fs.walk" "^1.2.3"
2937+
glob-parent "^5.1.2"
2938+
merge2 "^1.3.0"
2939+
micromatch "^4.0.4"
2940+
28862941
fast-json-stable-stringify@^2.0.0:
28872942
version "2.1.0"
28882943
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
@@ -3171,6 +3226,18 @@ globby@^11.0.0, globby@^11.0.1:
31713226
merge2 "^1.3.0"
31723227
slash "^3.0.0"
31733228

3229+
globby@^11.0.4:
3230+
version "11.1.0"
3231+
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
3232+
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
3233+
dependencies:
3234+
array-union "^2.1.0"
3235+
dir-glob "^3.0.1"
3236+
fast-glob "^3.2.9"
3237+
ignore "^5.2.0"
3238+
merge2 "^1.4.1"
3239+
slash "^3.0.0"
3240+
31743241
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.3, graceful-fs@^4.2.4, graceful-fs@^4.2.8:
31753242
version "4.2.8"
31763243
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
@@ -3350,6 +3417,11 @@ ignore@^5.1.4:
33503417
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
33513418
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
33523419

3420+
ignore@^5.2.0:
3421+
version "5.2.0"
3422+
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
3423+
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==
3424+
33533425
import-fresh@^3.0.0, import-fresh@^3.2.1:
33543426
version "3.3.0"
33553427
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"
@@ -4491,7 +4563,7 @@ merge-stream@^2.0.0:
44914563
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
44924564
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
44934565

4494-
merge2@^1.3.0:
4566+
merge2@^1.3.0, merge2@^1.4.1:
44954567
version "1.4.1"
44964568
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
44974569
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
@@ -6150,6 +6222,18 @@ trim-off-newlines@^1.0.0:
61506222
resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.2.tgz#65d52e4f4115992c0dac87220bdcc279fe58c422"
61516223
integrity sha512-DAnbtY4lNoOTLw05HLuvPoBFAGV4zOKQ9d1Q45JB+bcDwYIEkCr0xNgwKtygtKFBbRlFA/8ytkAM1V09QGWksg==
61526224

6225+
tslib@^1.8.1:
6226+
version "1.14.1"
6227+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
6228+
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
6229+
6230+
tsutils@^3.21.0:
6231+
version "3.21.0"
6232+
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.21.0.tgz#b48717d394cea6c1e096983eed58e9d61715b623"
6233+
integrity sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==
6234+
dependencies:
6235+
tslib "^1.8.1"
6236+
61536237
tunnel-agent@^0.6.0:
61546238
version "0.6.0"
61556239
resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"

0 commit comments

Comments
 (0)