|
| 1 | +const globals = require("globals"); |
| 2 | +const { defineConfig, globalIgnores } = require("eslint/config"); |
| 3 | + |
| 4 | +const commonRules = { |
| 5 | + // curly: true |
| 6 | + curly: "error", |
| 7 | + // eqeqeq: true + eqnull: true |
| 8 | + eqeqeq: ["error", "always", { null: "ignore" }], |
| 9 | + // immed: true (wrap immediately invoked function expressions) |
| 10 | + "wrap-iife": ["error", "any"], |
| 11 | + // latedef: true |
| 12 | + "no-use-before-define": [ |
| 13 | + "error", |
| 14 | + { functions: true, classes: true, variables: true }, |
| 15 | + ], |
| 16 | + // newcap: true |
| 17 | + "new-cap": "error", |
| 18 | + // noarg: true |
| 19 | + "no-caller": "error", |
| 20 | + // undef: true |
| 21 | + "no-undef": "error", |
| 22 | + // trailing: true |
| 23 | + "no-trailing-spaces": "error", |
| 24 | + // laxbreak: true - allow line breaks before operators |
| 25 | + "operator-linebreak": "off", |
| 26 | +}; |
| 27 | + |
| 28 | +module.exports = defineConfig([ |
| 29 | + globalIgnores([ |
| 30 | + "test/performance_test_pages/**/*.js", |
| 31 | + "test/fixtures/*.js", |
| 32 | + ]), |
| 33 | + { |
| 34 | + files: ["src/**/*.js"], |
| 35 | + languageOptions: { |
| 36 | + ecmaVersion: 2018, |
| 37 | + sourceType: "script", |
| 38 | + globals: { |
| 39 | + ...globals.browser, |
| 40 | + util: "readonly", |
| 41 | + proxies: "readonly", |
| 42 | + documentUtil: "readonly", |
| 43 | + documentHelper: "readonly", |
| 44 | + browser: "readonly", |
| 45 | + svg2image: "readonly", |
| 46 | + document2svg: "readonly", |
| 47 | + rasterize: "readonly", |
| 48 | + // external dependencies |
| 49 | + url: "readonly", |
| 50 | + xmlserializer: "readonly", |
| 51 | + sanedomparsererror: "readonly", |
| 52 | + inlineresources: "readonly", |
| 53 | + }, |
| 54 | + }, |
| 55 | + rules: { |
| 56 | + ...commonRules, |
| 57 | + // unused: true - but allow exported module-level vars |
| 58 | + "no-unused-vars": [ |
| 59 | + "error", |
| 60 | + { |
| 61 | + varsIgnorePattern: |
| 62 | + "^(util|proxies|documentUtil|documentHelper|browser|svg2image|document2svg|rasterize|rasterizeHTML)$", |
| 63 | + }, |
| 64 | + ], |
| 65 | + // strict: true |
| 66 | + strict: ["error", "function"], |
| 67 | + }, |
| 68 | + }, |
| 69 | + { |
| 70 | + files: ["test/**/*.js"], |
| 71 | + languageOptions: { |
| 72 | + ecmaVersion: 2018, |
| 73 | + sourceType: "script", |
| 74 | + globals: { |
| 75 | + ...globals.browser, |
| 76 | + ...globals.node, |
| 77 | + Promise: true, |
| 78 | + // console etc from devel |
| 79 | + console: true, |
| 80 | + alert: true, |
| 81 | + // jasmine globals |
| 82 | + jasmine: true, |
| 83 | + describe: true, |
| 84 | + it: true, |
| 85 | + xit: true, |
| 86 | + beforeEach: true, |
| 87 | + afterEach: true, |
| 88 | + expect: true, |
| 89 | + fail: true, |
| 90 | + spyOn: true, |
| 91 | + // project test helpers |
| 92 | + ifNotInWebkitOrBlinkIt: true, |
| 93 | + testHelper: true, |
| 94 | + diffHelper: true, |
| 95 | + // project globals |
| 96 | + util: true, |
| 97 | + proxies: true, |
| 98 | + documentUtil: true, |
| 99 | + documentHelper: true, |
| 100 | + browser: true, |
| 101 | + svg2image: true, |
| 102 | + document2svg: true, |
| 103 | + rasterize: true, |
| 104 | + rasterizeHTML: true, |
| 105 | + imagediff: true, |
| 106 | + // external dependencies |
| 107 | + inlineresources: true, |
| 108 | + isEqual: true, |
| 109 | + }, |
| 110 | + }, |
| 111 | + rules: { |
| 112 | + ...commonRules, |
| 113 | + // unused: true - allow unused function parameters (common in test callbacks) |
| 114 | + "no-unused-vars": ["error", { args: "none" }], |
| 115 | + // strict: true - disabled in test files as they have mixed patterns |
| 116 | + strict: "off", |
| 117 | + }, |
| 118 | + }, |
| 119 | + { |
| 120 | + files: ["Gruntfile.js"], |
| 121 | + languageOptions: { |
| 122 | + ecmaVersion: 2018, |
| 123 | + sourceType: "script", |
| 124 | + globals: { |
| 125 | + ...globals.node, |
| 126 | + module: true, |
| 127 | + }, |
| 128 | + }, |
| 129 | + rules: { |
| 130 | + ...commonRules, |
| 131 | + "no-unused-vars": "error", |
| 132 | + strict: "off", |
| 133 | + }, |
| 134 | + }, |
| 135 | +]); |
0 commit comments