Skip to content

Commit

Permalink
feat: re-export flat configs "flat/*"
Browse files Browse the repository at this point in the history
long-time plan:

v6: no action
v7: rename 'flat/*' => '*'; eslintrc config '*' => 'legacy/*'?
v8~: remove eslintrc supports
  • Loading branch information
aladdin-add committed Mar 28, 2024
1 parent f4d8cb1 commit 058a505
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 50 deletions.
11 changes: 6 additions & 5 deletions configs/all-type-checked.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* @deprecated use 'flat/all-type-checked' instead
* @author 唯然<weiran.zsd@outlook.com>
*/
'use strict';

Check failure on line 5 in configs/all-type-checked.js

View workflow job for this annotation

GitHub Actions / lint

Expected newline before "use strict" directive

Check failure on line 5 in configs/all-type-checked.js

View workflow job for this annotation

GitHub Actions / lint

Expected newline before "use strict" directive

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['all-type-checked'].rules,
};
module.exports = plugin.configs['flat/all-type-checked']

Check failure on line 9 in configs/all-type-checked.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 9 in configs/all-type-checked.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
8 changes: 3 additions & 5 deletions configs/all.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @fileoverview the `all` config for `eslint.config.js`
* @deprecated use 'flat/all' instead
* @author 唯然<weiran.zsd@outlook.com>
*/

'use strict';

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.all.rules,
};
module.exports = plugin.configs['flat/all']

Check failure on line 11 in configs/all.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 11 in configs/all.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
8 changes: 3 additions & 5 deletions configs/recommended.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @fileoverview the `recommended` config for `eslint.config.js`
* @deprecated use 'flat/recommended' instead
* @author 唯然<weiran.zsd@outlook.com>
*/

'use strict';

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.recommended.rules,
};
module.exports = plugin.configs['flat/recommended']

Check failure on line 11 in configs/recommended.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 11 in configs/recommended.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
8 changes: 3 additions & 5 deletions configs/rules-recommended.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @fileoverview the `rules-recommended` config for `eslint.config.js`
* @deprecated use 'flat/rules-recommended' instead
* @author 唯然<weiran.zsd@outlook.com>
*/

'use strict';

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['rules-recommended'].rules,
};
module.exports = plugin.configs['flat/rules-recommended']

Check failure on line 11 in configs/rules-recommended.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 11 in configs/rules-recommended.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
8 changes: 3 additions & 5 deletions configs/rules.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @fileoverview the `rules` config for `eslint.config.js`
* @deprecated use 'flat/rules' instead
* @author 唯然<weiran.zsd@outlook.com>
*/

'use strict';

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.rules.rules,
};
module.exports = plugin.configs['flat/rules']

Check failure on line 11 in configs/rules.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 11 in configs/rules.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
8 changes: 3 additions & 5 deletions configs/tests-recommended.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @fileoverview the `tests-recommended` config for `eslint.config.js`
* @deprecated use 'flat/tests-recommended' instead
* @author 唯然<weiran.zsd@outlook.com>
*/

'use strict';

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs['tests-recommended'].rules,
};
module.exports = plugin.configs['flat/tests-recommended']

Check failure on line 11 in configs/tests-recommended.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 11 in configs/tests-recommended.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
8 changes: 3 additions & 5 deletions configs/tests.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* @fileoverview the `tests` config for `eslint.config.js`
* @deprecated use 'flat/tests' instead
* @author 唯然<weiran.zsd@outlook.com>
*/

'use strict';

const mod = require('../lib/index.js');
const plugin = require('../lib/index.js');

module.exports = {
plugins: { 'eslint-plugin': mod },
rules: mod.configs.tests.rules,
};
module.exports = plugin.configs['flat/tests']

Check failure on line 11 in configs/tests.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 11 in configs/tests.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
38 changes: 30 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ const allRules = Object.fromEntries(
])
);

module.exports.meta = {
name: packageMetadata.name,
version: packageMetadata.version,
};

module.exports.rules = allRules;
const plugin = {
meta: {
name: packageMetadata.name,
version: packageMetadata.version,
},
rules: allRules,
configs: {}, // assigned later
}

Check failure on line 52 in lib/index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

Check failure on line 52 in lib/index.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

module.exports.configs = Object.keys(configFilters).reduce(
// eslintrc configs
Object.assign(plugin.configs, Object.keys(configFilters).reduce(

Check failure on line 55 in lib/index.js

View workflow job for this annotation

GitHub Actions / lint

Replace `plugin.configs,·Object.keys(configFilters).reduce(⏎··` with `⏎··plugin.configs,⏎··Object.keys(configFilters).reduce(`

Check failure on line 55 in lib/index.js

View workflow job for this annotation

GitHub Actions / lint

Replace `plugin.configs,·Object.keys(configFilters).reduce(⏎··` with `⏎··plugin.configs,⏎··Object.keys(configFilters).reduce(`
(configs, configName) => {
return Object.assign(configs, {
[configName]: {
Expand All @@ -63,4 +66,23 @@ module.exports.configs = Object.keys(configFilters).reduce(
});
},
{}
);
));

// flat configs
Object.assign(plugin.configs, Object.keys(configFilters).reduce(
(configs, configName) => {
return Object.assign(configs, {
[`flat/${configName}`]: {
plugins: { 'eslint-plugin': plugin},
rules: Object.fromEntries(
Object.keys(allRules)
.filter((ruleName) => configFilters[configName](allRules[ruleName]))
.map((ruleName) => [`${PLUGIN_NAME}/${ruleName}`, 'error'])
),
},
});
},
{}
));

module.exports = plugin;
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@eslint/eslintrc": "^2.0.2",
"@eslint/js": "^8.37.0",
"@eslint/js": "^8.57.0",
"@release-it/conventional-changelog": "^4.3.0",
"@types/eslint": "^8.56.2",
"@types/eslint": "^8.56.6",
"@types/estree": "^1.0.5",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"chai": "^4.3.6",
"dirty-chai": "^2.0.1",
"eslint": "^8.23.0",
"eslint": "^8.57.0",
"eslint-config-not-an-aardvark": "^2.1.0",
"eslint-config-prettier": "^8.5.0",
"eslint-doc-generator": "^1.7.0",
Expand All @@ -78,13 +78,13 @@
"husky": "^8.0.1",
"lodash": "^4.17.21",
"markdownlint-cli": "^0.39.0",
"mocha": "^10.0.0",
"npm-package-json-lint": "^7.0.0",
"npm-run-all2": "^5.0.0",
"mocha": "^10.4.0",
"npm-package-json-lint": "^7.1.0",
"npm-run-all2": "^6.1.2",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
"release-it": "^14.14.3",
"typescript": "^5.1.3"
"typescript": "^5.4.3"
},
"peerDependencies": {
"eslint": ">=7.0.0"
Expand Down

0 comments on commit 058a505

Please sign in to comment.