Skip to content

Commit 12a9f40

Browse files
committed
fix(plugin): Ensure rendered configs do not contain context-dependent paths
1 parent 6f3e765 commit 12a9f40

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/eslint-plugin-zillow/lib/get-computed-config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,10 @@ function getComputedConfig(baseConfig) {
1717
delete computed.filePath;
1818
delete computed.baseDirectory;
1919

20+
// un-resolve parser (re-resolved during re-export)
21+
if (computed.parser && baseConfig.parser && computed.parser !== baseConfig.parser) {
22+
computed.parser = baseConfig.parser;
23+
}
24+
2025
return computed;
2126
}

packages/eslint-plugin-zillow/test/eslint-plugin-zillow.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// ensure up-to-date JSON
44
require('../lib/render-configs');
55

6+
const fs = require('fs');
7+
const path = require('path');
8+
69
const { configs, processors, rules } = require('..');
710

811
describe('eslint-plugin-zillow', () => {
@@ -49,13 +52,25 @@ describe('eslint-plugin-zillow', () => {
4952
],
5053
},
5154
recommended: {
52-
parser: expect.stringContaining('babel-eslint'),
55+
parser: require.resolve('babel-eslint'),
5356
rules: {
5457
'zillow/react/jsx-indent': ['off', 4],
5558
'max-len': ['warn', 100, 4, { ignoreComments: false }],
5659
'zillow/import/prefer-default-export': ['off'],
5760
},
5861
},
62+
typescript: {
63+
overrides: [
64+
{
65+
files: ['**/*.ts?(x)'],
66+
parser: require.resolve('@typescript-eslint/parser'),
67+
plugins: ['zillow'],
68+
rules: {
69+
'zillow/@typescript-eslint/await-thenable': ['error'],
70+
},
71+
},
72+
],
73+
},
5974
});
6075

6176
const importResolverConfig = configs.recommended.settings['import/resolver'];
@@ -103,3 +118,28 @@ describe('eslint-plugin-zillow', () => {
103118
});
104119
});
105120
});
121+
122+
describe('rendered config', () => {
123+
// can't use require() because entry mutates those modules :P
124+
const readJSON = filePath =>
125+
JSON.parse(fs.readFileSync(path.resolve(__dirname, filePath), 'utf8'));
126+
127+
describe('recommended.json', () => {
128+
const renderedConfigRecommended = readJSON('../lib/configs/recommended.json');
129+
130+
it('has unresolved parser', () => {
131+
expect(renderedConfigRecommended).toHaveProperty('parser', 'babel-eslint');
132+
});
133+
});
134+
135+
describe('typescript.json', () => {
136+
const renderedConfigTypescript = readJSON('../lib/configs/typescript.json');
137+
138+
it('has unresolved parser', () => {
139+
expect(renderedConfigTypescript.overrides[0]).toHaveProperty(
140+
'parser',
141+
'@typescript-eslint/parser'
142+
);
143+
});
144+
});
145+
});

0 commit comments

Comments
 (0)