* Gets the singleton ESLint instance, initializing it if necessary. * Initializing involves reading the ESLint configuration from disk and * modifying it according to the needs of code fence removal. * * @returns {ESLint} The singleton ESLint instance.
()
| 83 | * @returns {ESLint} The singleton ESLint instance. |
| 84 | */ |
| 85 | function getESLintInstance() { |
| 86 | if (!eslintInstance) { |
| 87 | const eslintrc = require('./.eslintrc.js'); |
| 88 | |
| 89 | eslintrc.overrides.forEach((override) => { |
| 90 | const rules = override.rules ?? {}; |
| 91 | |
| 92 | // We don't want linting to fail for purely stylistic reasons. |
| 93 | rules['prettier/prettier'] = 'off'; |
| 94 | // Sometimes we use `let` instead of `const` to assign variables depending on |
| 95 | // the build type. |
| 96 | rules['prefer-const'] = 'off'; |
| 97 | |
| 98 | override.rules = rules; |
| 99 | }); |
| 100 | |
| 101 | // also override the rules section |
| 102 | // We don't want linting to fail for purely stylistic reasons. |
| 103 | eslintrc.rules['prettier/prettier'] = 0; |
| 104 | // Sometimes we use `let` instead of `const` to assign variables depending on |
| 105 | // the build type. |
| 106 | eslintrc.rules['prefer-const'] = 0; |
| 107 | |
| 108 | // Remove all test-related overrides. We will never lint test files here. |
| 109 | eslintrc.overrides = eslintrc.overrides.filter( |
| 110 | (override) => |
| 111 | !( |
| 112 | (override.extends && |
| 113 | override.extends.find( |
| 114 | (configName) => |
| 115 | configName.includes('jest') || configName.includes('mocha'), |
| 116 | )) || |
| 117 | (override.plugins && |
| 118 | override.plugins.find((pluginName) => pluginName.includes('jest'))) |
| 119 | ), |
| 120 | ); |
| 121 | |
| 122 | eslintInstance = new ESLint({ baseConfig: eslintrc, useEslintrc: false }); |
| 123 | } |
| 124 | return eslintInstance; |
| 125 | } |