diff --git a/mailpoet/eslint.config.js b/mailpoet/eslint.config.js new file mode 100644 index 0000000000..6caf87110e --- /dev/null +++ b/mailpoet/eslint.config.js @@ -0,0 +1,11 @@ +const es5Config = require('@mailpoet/eslint-config/eslint-es5.config'); + +module.exports = [ + { + ignores: ['assets/js/src/vendor/**'], + }, + ...es5Config.map((config) => ({ + ...config, + files: ['assets/js/src/**/*.js'], + })), +]; diff --git a/mailpoet/package.json b/mailpoet/package.json index dcf766a2a9..be41df0b7b 100644 --- a/mailpoet/package.json +++ b/mailpoet/package.json @@ -4,11 +4,10 @@ "extends @wordpress/browserslist-config" ], "scripts": { - "lint": "pnpm run lint6 && pnpm run lint-ts && pnpm run lint5 && pnpm run lint-tests", - "lint6": "eslint -c ../packages/js/eslint-config/.eslintrc.es6.js --max-warnings 0 'assets/js/src/**/*.jsx' 'tests/javascript/**/*.js'", - "lint-ts": "eslint -c ../packages/js/eslint-config/.eslintrc.ts.js --max-warnings 0 'assets/js/src/**/*.tsx' 'assets/js/src/**/*.ts'", - "lint5": "eslint -c ../packages/js/eslint-config/.eslintrc.es5.js --max-warnings 0 'assets/js/src/**/*.js' 'webpack.config.js'", - "lint-tests": "eslint -c ../packages/js/eslint-config/.eslintrc.tests_newsletter_editor.js --max-warnings 0 'tests/javascript_newsletter_editor'", + "lint": "eslint --max-warnings 0 'assets/js/src/**' && pnpm run lint6 && pnpm run lint-ts && pnpm run lint-tests", + "lint6": "ESLINT_USE_FLAT_CONFIG=false eslint -c ../packages/js/eslint-config/.eslintrc.es6.js --max-warnings 0 'assets/js/src/**/*.jsx' 'tests/javascript/**/*.js'", + "lint-ts": "ESLINT_USE_FLAT_CONFIG=false eslint -c ../packages/js/eslint-config/.eslintrc.ts.js --max-warnings 0 'assets/js/src/**/*.tsx' 'assets/js/src/**/*.ts'", + "lint-tests": "ESLINT_USE_FLAT_CONFIG=false eslint -c ../packages/js/eslint-config/.eslintrc.tests_newsletter_editor.js --max-warnings 0 'tests/javascript_newsletter_editor'", "autoprefixer": "postcss assets/dist/css/*.css --use autoprefixer --no-map --replace", "scss": "sass assets/css/src/:assets/dist/css/ --style compressed", "stylelint": "stylelint --fix", @@ -22,10 +21,10 @@ }, "lint-staged": { "*.{scss,css}": "pnpm run stylelint", - "!(*spec).js": "eslint -c ../packages/js/eslint-config/.eslintrc.es5.js --max-warnings 0", - "*.jsx": "eslint -c ../packages/js/eslint-config/.eslintrc.es6.js --max-warnings 0", - "*.{tsx,ts}": "eslint -c ../packages/js/eslint-config/.eslintrc.ts.js --max-warnings 0", - "**/newsletter_editor/**/*spec.js": "eslint -c ../packages/js/eslint-config/.eslintrc.tests_newsletter_editor.js --max-warnings 0", + "!(*spec).js": "eslint --max-warnings 0", + "*.jsx": "ESLINT_USE_FLAT_CONFIG=false eslint -c ../packages/js/eslint-config/.eslintrc.es6.js --max-warnings 0", + "*.{tsx,ts}": "ESLINT_USE_FLAT_CONFIG=false eslint -c ../packages/js/eslint-config/.eslintrc.ts.js --max-warnings 0", + "**/newsletter_editor/**/*spec.js": "ESLINT_USE_FLAT_CONFIG=false eslint -c ../packages/js/eslint-config/.eslintrc.tests_newsletter_editor.js --max-warnings 0", "*.php": [ "phplint", "./do qa:code-sniffer", diff --git a/packages/js/eslint-config/.eslintrc.es5.js b/packages/js/eslint-config/.eslintrc.es5.js deleted file mode 100644 index 57b74483df..0000000000 --- a/packages/js/eslint-config/.eslintrc.es5.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - extends: ['airbnb/legacy', 'prettier'], - env: { - amd: true, - browser: true, - }, - plugins: ['eslint-plugin-import'], - parser: '@babel/eslint-parser', - parserOptions: { - ecmaVersion: 6, - sourceType: 'module', - }, - rules: { - 'import/prefer-default-export': 0, // we want to stop using default exports and start using named exports - 'no-underscore-dangle': 0, // Backbone uses underscores, we cannot remove them - 'import/no-default-export': 1, // no default exports - }, -}; diff --git a/packages/js/eslint-config/eslint-es5.config.js b/packages/js/eslint-config/eslint-es5.config.js new file mode 100644 index 0000000000..fc13646a95 --- /dev/null +++ b/packages/js/eslint-config/eslint-es5.config.js @@ -0,0 +1,36 @@ +const babelParser = require('@babel/eslint-parser'); +const FlatCompat = require('@eslint/eslintrc').FlatCompat; +const airbnbLegacyConfig = require('eslint-config-airbnb/legacy'); +const prettierConfig = require('eslint-config-prettier'); +const importPlugin = require('eslint-plugin-import'); +const globals = require('globals'); + +// compat configs +const compat = new FlatCompat({ baseDirectory: __dirname }); +const airbnbLegacyCompatConfig = compat.config(airbnbLegacyConfig); +const prettierCompatConfig = compat.config(prettierConfig); + +module.exports = [ + ...airbnbLegacyCompatConfig, + ...prettierCompatConfig, + { + languageOptions: { + parser: babelParser, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + }, + globals: { + ...globals.browser, + }, + }, + plugins: { + import: importPlugin, + }, + rules: { + 'import/prefer-default-export': 0, // we want to stop using default exports and start using named exports + 'no-underscore-dangle': 0, // Backbone uses underscores, we cannot remove them + 'import/no-default-export': 1, // no default exports + }, + }, +];