|
| 1 | +const js = require("@eslint/js"); |
| 2 | +const vuePlugin = require("eslint-plugin-vue"); |
| 3 | +const globals = require("globals"); |
| 4 | +const babelParser = require("@babel/eslint-parser"); |
| 5 | + |
| 6 | +/** @type {import('eslint').Linter.Config[]} */ |
| 7 | +module.exports = [ |
| 8 | + // Ignore patterns from .eslintignore |
| 9 | + { |
| 10 | + ignores: [ |
| 11 | + ".*", |
| 12 | + "*.config.js", |
| 13 | + "*.config.mjs", |
| 14 | + "conf/", |
| 15 | + "config/", |
| 16 | + "docker/", |
| 17 | + "infogami/", |
| 18 | + "node_modules/", |
| 19 | + "scripts/", |
| 20 | + "static/build/", |
| 21 | + "build/", |
| 22 | + "coverage/", |
| 23 | + "provisioning/", |
| 24 | + "vendor/", |
| 25 | + "tests/screenshots/", |
| 26 | + "venv/", |
| 27 | + "eslint.config.cjs", |
| 28 | + ], |
| 29 | + }, |
| 30 | + |
| 31 | + // Configuration for build and config files (CommonJS) - MUST come before js.configs.recommended |
| 32 | + { |
| 33 | + files: [ |
| 34 | + "webpack.config.js", |
| 35 | + "webpack.config.css.js", |
| 36 | + "vue.config.js", |
| 37 | + "openlibrary/components/dev/serve-component.js", |
| 38 | + "conf/svgo.config.js", |
| 39 | + "stories/.storybook/main.js", |
| 40 | + ], |
| 41 | + languageOptions: { |
| 42 | + sourceType: "script", |
| 43 | + ecmaVersion: "latest", |
| 44 | + globals: { |
| 45 | + ...globals.node, |
| 46 | + }, |
| 47 | + }, |
| 48 | + rules: { |
| 49 | + "no-console": "off", |
| 50 | + }, |
| 51 | + }, |
| 52 | + |
| 53 | + // Configuration for Vite config files (ES modules) - MUST come before js.configs.recommended |
| 54 | + { |
| 55 | + files: [ |
| 56 | + "openlibrary/components/vite.config.mjs", |
| 57 | + "openlibrary/components/vite-lit.config.mjs", |
| 58 | + ], |
| 59 | + languageOptions: { |
| 60 | + ecmaVersion: "latest", |
| 61 | + sourceType: "module", |
| 62 | + globals: { |
| 63 | + ...globals.node, |
| 64 | + }, |
| 65 | + }, |
| 66 | + rules: { |
| 67 | + "no-console": "off", |
| 68 | + }, |
| 69 | + }, |
| 70 | + |
| 71 | + // Configuration for Storybook preview files (ES modules) - MUST come before js.configs.recommended |
| 72 | + { |
| 73 | + files: ["stories/.storybook/preview.js"], |
| 74 | + languageOptions: { |
| 75 | + sourceType: "module", |
| 76 | + ecmaVersion: "latest", |
| 77 | + globals: { |
| 78 | + ...globals.node, |
| 79 | + }, |
| 80 | + }, |
| 81 | + rules: { |
| 82 | + "no-console": "off", |
| 83 | + }, |
| 84 | + }, |
| 85 | + |
| 86 | + // Base recommended config |
| 87 | + js.configs.recommended, |
| 88 | + |
| 89 | + // Vue plugin configuration |
| 90 | + ...vuePlugin.configs["flat/recommended"], |
| 91 | + |
| 92 | + // Base configuration for all JS/Vue files (except config and build files) |
| 93 | + { |
| 94 | + files: ["**/*.js", "**/*.vue"], |
| 95 | + plugins: { |
| 96 | + "no-jquery": require("eslint-plugin-no-jquery"), |
| 97 | + }, |
| 98 | + languageOptions: { |
| 99 | + parserOptions: { |
| 100 | + sourceType: "module", |
| 101 | + ecmaVersion: "latest", |
| 102 | + babelOptions: { |
| 103 | + configFile: "./.babelrc", |
| 104 | + }, |
| 105 | + }, |
| 106 | + globals: { |
| 107 | + ...globals.browser, |
| 108 | + $: "readonly", |
| 109 | + jQuery: "readonly", |
| 110 | + }, |
| 111 | + }, |
| 112 | + rules: { |
| 113 | + "prefer-template": "error", |
| 114 | + eqeqeq: ["error", "always"], |
| 115 | + quotes: ["error", "single"], |
| 116 | + "eol-last": ["error", "always"], |
| 117 | + indent: 2, |
| 118 | + "no-console": "error", |
| 119 | + "no-mixed-spaces-and-tabs": "error", |
| 120 | + "no-extra-semi": "error", |
| 121 | + "no-redeclare": "error", |
| 122 | + "no-trailing-spaces": "error", |
| 123 | + "no-undef": "error", |
| 124 | + "no-unused-vars": [ |
| 125 | + "error", |
| 126 | + { |
| 127 | + caughtErrors: "none", |
| 128 | + }, |
| 129 | + ], |
| 130 | + "no-useless-escape": "error", |
| 131 | + "space-in-parens": "error", |
| 132 | + "vars-on-top": "error", |
| 133 | + "prefer-const": "error", |
| 134 | + "template-curly-spacing": "error", |
| 135 | + "quote-props": ["error", "as-needed"], |
| 136 | + "keyword-spacing": ["error", { before: true, after: true }], |
| 137 | + "key-spacing": ["error", { mode: "strict" }], |
| 138 | + "vue/no-mutating-props": "off", |
| 139 | + "vue/multi-word-component-names": [ |
| 140 | + "error", |
| 141 | + { |
| 142 | + ignores: ["Bookshelf", "Shelf"], |
| 143 | + }, |
| 144 | + ], |
| 145 | + // jQuery deprecated rules (from plugin:no-jquery/deprecated) |
| 146 | + "no-jquery/no-box-model": "warn", |
| 147 | + "no-jquery/no-browser": "warn", |
| 148 | + "no-jquery/no-live": "warn", |
| 149 | + "no-jquery/no-sub": "warn", |
| 150 | + "no-jquery/no-selector-prop": "warn", |
| 151 | + "no-jquery/no-and-self": "warn", |
| 152 | + "no-jquery/no-error-shorthand": "warn", |
| 153 | + "no-jquery/no-load-shorthand": "warn", |
| 154 | + "no-jquery/no-on-ready": "warn", |
| 155 | + "no-jquery/no-size": "warn", |
| 156 | + "no-jquery/no-unload-shorthand": "warn", |
| 157 | + "no-jquery/no-support": "warn", |
| 158 | + "no-jquery/no-context-prop": "warn", |
| 159 | + "no-jquery/no-bind": "warn", |
| 160 | + "no-jquery/no-delegate": "warn", |
| 161 | + "no-jquery/no-fx-interval": "warn", |
| 162 | + "no-jquery/no-parse-json": "warn", |
| 163 | + "no-jquery/no-ready-shorthand": "warn", |
| 164 | + "no-jquery/no-unique": "warn", |
| 165 | + "no-jquery/no-hold-ready": "warn", |
| 166 | + "no-jquery/no-is-array": "warn", |
| 167 | + "no-jquery/no-node-name": "warn", |
| 168 | + "no-jquery/no-camel-case": "warn", |
| 169 | + "no-jquery/no-event-shorthand": ["warn", {}], |
| 170 | + "no-jquery/no-is-function": "warn", |
| 171 | + "no-jquery/no-is-numeric": "warn", |
| 172 | + "no-jquery/no-is-window": "warn", |
| 173 | + "no-jquery/no-now": "warn", |
| 174 | + "no-jquery/no-proxy": "warn", |
| 175 | + "no-jquery/no-type": "warn", |
| 176 | + "no-jquery/no-sizzle": [ |
| 177 | + "warn", |
| 178 | + { allowPositional: false, allowOther: true }, |
| 179 | + ], |
| 180 | + "no-jquery/no-trim": "warn", |
| 181 | + }, |
| 182 | + }, |
| 183 | + |
| 184 | + // Vue-specific configuration |
| 185 | + { |
| 186 | + files: ["**/*.vue"], |
| 187 | + languageOptions: { |
| 188 | + parserOptions: { |
| 189 | + parser: babelParser, |
| 190 | + sourceType: "module", |
| 191 | + ecmaVersion: "latest", |
| 192 | + babelOptions: { |
| 193 | + configFile: "./.babelrc", |
| 194 | + }, |
| 195 | + }, |
| 196 | + }, |
| 197 | + }, |
| 198 | + |
| 199 | + // JavaScript-specific configuration |
| 200 | + { |
| 201 | + files: ["**/*.js"], |
| 202 | + languageOptions: { |
| 203 | + parser: babelParser, |
| 204 | + parserOptions: { |
| 205 | + sourceType: "module", |
| 206 | + ecmaVersion: "latest", |
| 207 | + babelOptions: { |
| 208 | + configFile: "./.babelrc", |
| 209 | + }, |
| 210 | + }, |
| 211 | + }, |
| 212 | + }, |
| 213 | + |
| 214 | + // Configuration for test files |
| 215 | + { |
| 216 | + files: ["tests/unit/**/*.{js,vue}", "tests/unit/js/setup.js"], |
| 217 | + languageOptions: { |
| 218 | + globals: { |
| 219 | + ...globals.es2021, |
| 220 | + ...globals.jest, |
| 221 | + ...globals.node, |
| 222 | + }, |
| 223 | + }, |
| 224 | + }, |
| 225 | +]; |
0 commit comments