Skip to content

Commit

Permalink
[New] added jsx-runtime config, for the modern JSX runtime transform
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 23, 2021
1 parent 7b35ee7 commit c8917b0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`jsx-pascal-case`]: support `allowNamespace` option ([#2917][] @kev-y-huang)
* [`jsx-newline`]: Add prevent option ([#2935][] @jsphstls)
* [`no-unstable-nested-components`]: Prevent creating unstable components inside components ([#2750][] @AriPerkkio)
* added `jsx-runtime` config, for the modern JSX runtime transform (@ljharb)

### Fixed
* [`jsx-no-constructed-context-values`]: avoid a crash with `as X` TS code ([#2894][] @ljharb)
Expand Down
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ module.exports = {
}
},
rules: activeRulesConfig
},
'jsx-runtime': {
plugins: [
'react'
],
parserOptions: {
ecmaFeatures: {
jsx: true
}
},
rules: {
'react/react-in-jsx-scope': 0,
'react/jsx-uses-react': 0
}
}
}
};
43 changes: 30 additions & 13 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ describe('deprecated rules', () => {

describe('configurations', () => {
it('should export a ‘recommended’ configuration', () => {
assert(plugin.configs.recommended);
Object.keys(plugin.configs.recommended.rules).forEach((configName) => {
assert.equal(configName.indexOf('react/'), 0);
const ruleName = configName.slice('react/'.length);
assert(plugin.rules[ruleName]);
const configName = 'recommended';
assert(plugin.configs[configName]);

Object.keys(plugin.configs[configName].rules).forEach((ruleName) => {
assert.ok(ruleName.startsWith('react/'));
const subRuleName = ruleName.slice('react/'.length);
assert(plugin.rules[subRuleName]);
});

ruleFiles.forEach((ruleName) => {
const inRecommendedConfig = !!plugin.configs.recommended.rules[`react/${ruleName}`];
const isRecommended = plugin.rules[ruleName].meta.docs.recommended;
const inRecommendedConfig = !!plugin.configs[configName].rules[`react/${ruleName}`];
const isRecommended = plugin.rules[ruleName].meta.docs[configName];
if (inRecommendedConfig) {
assert(isRecommended, `${ruleName} metadata should mark it as recommended`);
} else {
Expand All @@ -57,17 +59,32 @@ describe('configurations', () => {
});

it('should export an ‘all’ configuration', () => {
assert(plugin.configs.all);
const configName = 'all';
assert(plugin.configs[configName]);

Object.keys(plugin.configs.all.rules).forEach((configName) => {
assert.equal(configName.indexOf('react/'), 0);
assert.equal(plugin.configs.all.rules[configName], 2);
Object.keys(plugin.configs[configName].rules).forEach((ruleName) => {
assert.ok(ruleName.startsWith('react/'));
assert.equal(plugin.configs[configName].rules[ruleName], 2);
});

ruleFiles.forEach((ruleName) => {
const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
const inAllConfig = Boolean(plugin.configs.all.rules[`react/${ruleName}`]);
assert(inDeprecatedRules ^ inAllConfig); // eslint-disable-line no-bitwise
const inConfig = typeof plugin.configs[configName].rules[`react/${ruleName}`] !== 'undefined';
assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise
});
});

it('should export a \'jsx-runtime\' configuration', () => {
const configName = 'jsx-runtime';
assert(plugin.configs[configName]);

Object.keys(plugin.configs[configName].rules).forEach((ruleName) => {
assert.ok(ruleName.startsWith('react/'));
assert.equal(plugin.configs[configName].rules[ruleName], 0);

const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]);
const inConfig = typeof plugin.configs[configName].rules[ruleName] !== 'undefined';
assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise
});
});
});

0 comments on commit c8917b0

Please sign in to comment.