diff --git a/CHANGELOG.md b/CHANGELOG.md index cb836c853a..9dc70bd90b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/index.js b/index.js index f5d9872cc0..8a0adf7f32 100644 --- a/index.js +++ b/index.js @@ -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 + } } } }; diff --git a/tests/index.js b/tests/index.js index ef18b6d3cc..c04936fa26 100644 --- a/tests/index.js +++ b/tests/index.js @@ -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 { @@ -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 }); }); });