From c03d25be9dc68112df5e03142f5c8545c1f8db4e Mon Sep 17 00:00:00 2001 From: Grace Park Date: Mon, 25 Nov 2024 13:08:37 -0800 Subject: [PATCH] bring in filenames match regex to github --- README.md | 1 + eslint.config.js | 4 +--- lib/configs/flat/browser.js | 3 ++- lib/configs/flat/internal.js | 3 ++- lib/configs/flat/react.js | 3 ++- lib/configs/flat/recommended.js | 6 ++---- lib/configs/flat/typescript.js | 3 ++- lib/configs/recommended.js | 2 +- lib/plugin.js | 1 + test-examples/flat/eslint.config.mjs | 8 ++++---- test-examples/flat/package.json | 2 +- 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c69717b4..e98fc8e0 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,7 @@ This config will be interpreted in the following way: | [async-currenttarget](docs/rules/async-currenttarget.md) | disallow `event.currentTarget` calls inside of async functions | 🔍 | | | | [async-preventdefault](docs/rules/async-preventdefault.md) | disallow `event.preventDefault` calls inside of async functions | 🔍 | | | | [authenticity-token](docs/rules/authenticity-token.md) | disallow usage of CSRF tokens in JavaScript | 🔐 | | | +| [filenames-match-regex](docs/rules/filenames-match-regex.md) | ensure filenames match a regex naming convention | ✅ | | | | [get-attribute](docs/rules/get-attribute.md) | disallow wrong usage of attribute names | 🔍 | 🔧 | | | [js-class-name](docs/rules/js-class-name.md) | enforce a naming convention for js- prefixed classes | 🔐 | | | | [no-blur](docs/rules/no-blur.md) | disallow usage of `Element.prototype.blur()` | 🔍 | | | diff --git a/eslint.config.js b/eslint.config.js index 3dc2832f..e5dae376 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,7 +1,6 @@ const globals = require('globals') const eslintPlugin = require('eslint-plugin-eslint-plugin') const importPlugin = require('eslint-plugin-import') -const filenames = require('eslint-plugin-filenames') const i18nTextPlugin = require('eslint-plugin-i18n-text') const recommendedGitHub = require('./lib/configs/flat/recommended') const {fixupPluginRules} = require('@eslint/compat') @@ -23,13 +22,12 @@ module.exports = [ plugins: { eslintPlugin, importPlugin, - filenamesPlugin: fixupPluginRules(filenames), 'i18n-text': fixupPluginRules(i18nTextPlugin), }, rules: { 'importPlugin/extensions': 'off', 'importPlugin/no-commonjs': 'off', - 'filenamesPlugin/match-regex': 'off', + 'github/filenames-match-regex': 'off', 'i18n-text/no-en': 'off', 'eslint-plugin/prefer-placeholders': 'off', 'eslint-plugin/test-case-shorthand-strings': 'off', diff --git a/lib/configs/flat/browser.js b/lib/configs/flat/browser.js index 17f2b74c..67ba85fe 100644 --- a/lib/configs/flat/browser.js +++ b/lib/configs/flat/browser.js @@ -2,6 +2,7 @@ const globals = require('globals') const github = require('../../plugin') const importPlugin = require('eslint-plugin-import') const escompatPlugin = require('eslint-plugin-escompat') +const {fixupPluginRules} = require('@eslint/compat') module.exports = { ...escompatPlugin.configs['flat/recommended'], @@ -10,7 +11,7 @@ module.exports = { ...globals.browser, }, }, - plugins: {importPlugin, escompatPlugin, github}, + plugins: {importPlugin, escompatPlugin, github: fixupPluginRules(github)}, rules: { 'escompatPlugin/no-dynamic-imports': 'off', 'github/async-currenttarget': 'error', diff --git a/lib/configs/flat/internal.js b/lib/configs/flat/internal.js index e3aa8e43..0ce81f51 100644 --- a/lib/configs/flat/internal.js +++ b/lib/configs/flat/internal.js @@ -1,7 +1,8 @@ const github = require('../../plugin') +const {fixupPluginRules} = require('@eslint/compat') module.exports = { - plugins: {github}, + plugins: {github: fixupPluginRules(github)}, rules: { 'github/authenticity-token': 'error', 'github/js-class-name': 'error', diff --git a/lib/configs/flat/react.js b/lib/configs/flat/react.js index 8d2e0f80..497505fc 100644 --- a/lib/configs/flat/react.js +++ b/lib/configs/flat/react.js @@ -1,5 +1,6 @@ const github = require('../../plugin') const jsxA11yPlugin = require('eslint-plugin-jsx-a11y') +const {fixupPluginRules} = require('@eslint/compat') module.exports = { ...jsxA11yPlugin.flatConfigs.recommended, @@ -11,7 +12,7 @@ module.exports = { }, }, }, - plugins: {github, jsxA11yPlugin}, + plugins: {github: fixupPluginRules(github), jsxA11yPlugin}, rules: { 'jsxA11yPlugin/role-supports-aria-props': 'off', // Override with github/a11y-role-supports-aria-props until https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/issues/910 is resolved 'github/a11y-aria-label-is-well-formatted': 'error', diff --git a/lib/configs/flat/recommended.js b/lib/configs/flat/recommended.js index 061260fa..31cb3400 100644 --- a/lib/configs/flat/recommended.js +++ b/lib/configs/flat/recommended.js @@ -3,7 +3,6 @@ const github = require('../../plugin') const prettierPlugin = require('eslint-plugin-prettier') const eslintComments = require('eslint-plugin-eslint-comments') const importPlugin = require('eslint-plugin-import') -const filenames = require('eslint-plugin-filenames') const i18nTextPlugin = require('eslint-plugin-i18n-text') const noOnlyTestsPlugin = require('eslint-plugin-no-only-tests') const {fixupPluginRules} = require('@eslint/compat') @@ -17,13 +16,12 @@ module.exports = { }, }, plugins: { - filenamesPlugin: fixupPluginRules(filenames), prettierPlugin, eslintComments, importPlugin, 'i18n-text': fixupPluginRules(i18nTextPlugin), noOnlyTestsPlugin, - github, + github: fixupPluginRules(github), }, rules: { 'constructor-super': 'error', @@ -34,7 +32,7 @@ module.exports = { 'eslintComments/no-unused-disable': 'error', 'eslintComments/no-unused-enable': 'error', 'eslintComments/no-use': ['error', {allow: ['eslint', 'eslint-disable-next-line', 'eslint-env', 'globals']}], - 'filenamesPlugin/match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'], + 'github/filenames-match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'], 'func-style': ['error', 'declaration', {allowArrowFunctions: true}], 'github/array-foreach': 'error', 'github/no-implicit-buggy-globals': 'error', diff --git a/lib/configs/flat/typescript.js b/lib/configs/flat/typescript.js index eb6b71fd..50cc6c05 100644 --- a/lib/configs/flat/typescript.js +++ b/lib/configs/flat/typescript.js @@ -2,12 +2,13 @@ const eslint = require('@eslint/js') const tseslint = require('typescript-eslint') const escompatPlugin = require('eslint-plugin-escompat') const github = require('../../plugin') +const {fixupPluginRules} = require('@eslint/compat') module.exports = tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommended, { languageOptions: { parser: tseslint.parser, }, - plugins: {'@typescript-eslint': tseslint.plugin, escompatPlugin, github}, + plugins: {'@typescript-eslint': tseslint.plugin, escompatPlugin, github: fixupPluginRules(github)}, rules: { camelcase: 'off', 'no-unused-vars': 'off', diff --git a/lib/configs/recommended.js b/lib/configs/recommended.js index cdbbd450..2ba51af6 100644 --- a/lib/configs/recommended.js +++ b/lib/configs/recommended.js @@ -18,7 +18,7 @@ module.exports = { 'eslint-comments/no-unused-disable': 'error', 'eslint-comments/no-unused-enable': 'error', 'eslint-comments/no-use': ['error', {allow: ['eslint', 'eslint-disable-next-line', 'eslint-env', 'globals']}], - 'filenames/match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'], + 'github/filenames-match-regex': ['error', '^[a-z0-9-]+(.[a-z0-9-]+)?$'], 'func-style': ['error', 'declaration', {allowArrowFunctions: true}], 'github/array-foreach': 'error', 'github/no-implicit-buggy-globals': 'error', diff --git a/lib/plugin.js b/lib/plugin.js index 3ed34175..eb25a25e 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -13,6 +13,7 @@ module.exports = { 'async-currenttarget': require('./rules/async-currenttarget'), 'async-preventdefault': require('./rules/async-preventdefault'), 'authenticity-token': require('./rules/authenticity-token'), + 'filenames-match-regex': require('./rules/filenames-match-regex'), 'get-attribute': require('./rules/get-attribute'), 'js-class-name': require('./rules/js-class-name'), 'no-blur': require('./rules/no-blur'), diff --git a/test-examples/flat/eslint.config.mjs b/test-examples/flat/eslint.config.mjs index db132c02..8bad9255 100644 --- a/test-examples/flat/eslint.config.mjs +++ b/test-examples/flat/eslint.config.mjs @@ -1,18 +1,18 @@ import github from 'eslint-plugin-github' export default [ - github.getFlatConfigs().browser, github.getFlatConfigs().recommended, - github.getFlatConfigs().react, - ...github.getFlatConfigs().typescript, + // github.getFlatConfigs().recommended, + // github.getFlatConfigs().react, + // ...github.getFlatConfigs().typescript, { files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'], ignores: ['eslint.config.mjs'], rules: { 'github/array-foreach': 'error', - 'github/async-preventdefault': 'warn', 'github/no-then': 'error', 'github/no-blur': 'error', + 'github/async-preventdefault': 'error', }, }, ] diff --git a/test-examples/flat/package.json b/test-examples/flat/package.json index 99ee6c96..ab18bedc 100644 --- a/test-examples/flat/package.json +++ b/test-examples/flat/package.json @@ -9,7 +9,7 @@ "@eslint/js": "^9.5.0", "@types/node": "^20.14.5", "cross-env": "^7.0.3", - "eslint": "^8.57.0", + "eslint": "^9.14.0", "eslint-plugin-github": "file:../..", "typescript": "^5.6.3", "typescript-eslint": "^8.12.2"