Skip to content

Commit c8917b0

Browse files
committed
[New] added jsx-runtime config, for the modern JSX runtime transform
1 parent 7b35ee7 commit c8917b0

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1111
* [`jsx-pascal-case`]: support `allowNamespace` option ([#2917][] @kev-y-huang)
1212
* [`jsx-newline`]: Add prevent option ([#2935][] @jsphstls)
1313
* [`no-unstable-nested-components`]: Prevent creating unstable components inside components ([#2750][] @AriPerkkio)
14+
* added `jsx-runtime` config, for the modern JSX runtime transform (@ljharb)
1415

1516
### Fixed
1617
* [`jsx-no-constructed-context-values`]: avoid a crash with `as X` TS code ([#2894][] @ljharb)

index.js

+14
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ module.exports = {
159159
}
160160
},
161161
rules: activeRulesConfig
162+
},
163+
'jsx-runtime': {
164+
plugins: [
165+
'react'
166+
],
167+
parserOptions: {
168+
ecmaFeatures: {
169+
jsx: true
170+
}
171+
},
172+
rules: {
173+
'react/react-in-jsx-scope': 0,
174+
'react/jsx-uses-react': 0
175+
}
162176
}
163177
}
164178
};

tests/index.js

+30-13
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ describe('deprecated rules', () => {
3838

3939
describe('configurations', () => {
4040
it('should export a ‘recommended’ configuration', () => {
41-
assert(plugin.configs.recommended);
42-
Object.keys(plugin.configs.recommended.rules).forEach((configName) => {
43-
assert.equal(configName.indexOf('react/'), 0);
44-
const ruleName = configName.slice('react/'.length);
45-
assert(plugin.rules[ruleName]);
41+
const configName = 'recommended';
42+
assert(plugin.configs[configName]);
43+
44+
Object.keys(plugin.configs[configName].rules).forEach((ruleName) => {
45+
assert.ok(ruleName.startsWith('react/'));
46+
const subRuleName = ruleName.slice('react/'.length);
47+
assert(plugin.rules[subRuleName]);
4648
});
4749

4850
ruleFiles.forEach((ruleName) => {
49-
const inRecommendedConfig = !!plugin.configs.recommended.rules[`react/${ruleName}`];
50-
const isRecommended = plugin.rules[ruleName].meta.docs.recommended;
51+
const inRecommendedConfig = !!plugin.configs[configName].rules[`react/${ruleName}`];
52+
const isRecommended = plugin.rules[ruleName].meta.docs[configName];
5153
if (inRecommendedConfig) {
5254
assert(isRecommended, `${ruleName} metadata should mark it as recommended`);
5355
} else {
@@ -57,17 +59,32 @@ describe('configurations', () => {
5759
});
5860

5961
it('should export an ‘all’ configuration', () => {
60-
assert(plugin.configs.all);
62+
const configName = 'all';
63+
assert(plugin.configs[configName]);
6164

62-
Object.keys(plugin.configs.all.rules).forEach((configName) => {
63-
assert.equal(configName.indexOf('react/'), 0);
64-
assert.equal(plugin.configs.all.rules[configName], 2);
65+
Object.keys(plugin.configs[configName].rules).forEach((ruleName) => {
66+
assert.ok(ruleName.startsWith('react/'));
67+
assert.equal(plugin.configs[configName].rules[ruleName], 2);
6568
});
6669

6770
ruleFiles.forEach((ruleName) => {
6871
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
69-
const inAllConfig = Boolean(plugin.configs.all.rules[`react/${ruleName}`]);
70-
assert(inDeprecatedRules ^ inAllConfig); // eslint-disable-line no-bitwise
72+
const inConfig = typeof plugin.configs[configName].rules[`react/${ruleName}`] !== 'undefined';
73+
assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise
74+
});
75+
});
76+
77+
it('should export a \'jsx-runtime\' configuration', () => {
78+
const configName = 'jsx-runtime';
79+
assert(plugin.configs[configName]);
80+
81+
Object.keys(plugin.configs[configName].rules).forEach((ruleName) => {
82+
assert.ok(ruleName.startsWith('react/'));
83+
assert.equal(plugin.configs[configName].rules[ruleName], 0);
84+
85+
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
86+
const inConfig = typeof plugin.configs[configName].rules[ruleName] !== 'undefined';
87+
assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise
7188
});
7289
});
7390
});

0 commit comments

Comments
 (0)