From 76d2778195c740a1b2b9b1784e54c13411cb8cf5 Mon Sep 17 00:00:00 2001 From: Nikhil Chelliah Date: Wed, 12 Oct 2022 19:08:26 -0400 Subject: [PATCH] fix(eslint): Improve the globs for JS files * Explicitly match file extensions in all globs, thus preventing eslint from trying to run on unsupported file types. * Include the defaults: `.js`, `.mjs`, and `.cjs` * Include`.jsx` * Include `.mustache`, since there are a couple JS template files with that suffix. * Fix some incorrect globs (`**.js` -> `**/*.js`) which were the source of some unexpected lint failures. --- .eslintrc.cjs | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 86afe0a4676..ec3240c4988 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,22 +1,24 @@ -const mongoFiles = ['ansible/playbooks/files/migrate_data.{js,mjs,cjs}'] +const jsSuffixes = '{js,mjs,cjs,jsx}' + +const mongoFiles = [`ansible/playbooks/files/migrate_data.${jsSuffixes}`] const nodeFiles = [ - '**/build.dflt.{js,mjs,cjs}', - '**/build.{js,mjs,cjs}', - '**/config/**', - '**/prebuild.{js,mjs,cjs}', - '**/prebuild/**', - '**/scripts/**', - 'packages/new-design/lib/**', - 'sites/backend/**', - 'sites/*/mdx/**', - 'sites/*/themes/**', + `**/build.dflt.${jsSuffixes}`, + `**/build.${jsSuffixes}`, + `**/config/**/*.${jsSuffixes}`, + `**/prebuild.${jsSuffixes}`, + `**/prebuild/**/*.${jsSuffixes}`, + `**/scripts/**/*.${jsSuffixes}`, + `packages/new-design/lib/**/*.${jsSuffixes}`, + `sites/backend/**/*.${jsSuffixes}`, + `sites/*/mdx/**/*.${jsSuffixes}`, + `sites/*/themes/**/*.${jsSuffixes}`, ] const frontendFiles = [ - '**/components/**', - '**/hooks/**', - '**/pages/**', - '**/page-templates/**', - 'packages/i18n/**/*.md/*.js', + `**/components/**/*.${jsSuffixes}`, + `**/hooks/**/*.${jsSuffixes}`, + `**/pages/**/*.${jsSuffixes}`, + `**/page-templates/**/*.${jsSuffixes}`, + `packages/i18n/**/*.md/*.${jsSuffixes}`, ] module.exports = { @@ -64,7 +66,7 @@ module.exports = { }, }, { - files: ['**'], + files: [`**/*.${jsSuffixes}{,.mustache}`], excludedFiles: [].concat(mongoFiles, nodeFiles, frontendFiles), env: { 'shared-node-browser': true, @@ -81,7 +83,7 @@ module.exports = { }, // Additional globals for JavaScript files that happen to contain Mocha tests { - files: ['**/tests/**', '**/*.test.mjs'], + files: [`**/tests/**/*.${jsSuffixes}`, `**/*.test.${jsSuffixes}`], env: { mocha: true, }, @@ -89,7 +91,7 @@ module.exports = { // JSON files { - files: ['*.json', '*.json5', '*.jsonc'], + files: ['**/*.{json,json5,jsonc}{,.mustache}'], extends: ['plugin:jsonc/recommended-with-jsonc'], parser: 'jsonc-eslint-parser', },