|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 4 | + * See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 5 | + * All rights not expressly granted are reserved. |
| 6 | + * |
| 7 | + * This software is distributed under the terms of the GNU General Public |
| 8 | + * License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 9 | + * |
| 10 | + * In applying this license CERN does not waive the privileges and immunities |
| 11 | + * granted to it by virtue of its status as an Intergovernmental Organization |
| 12 | + * or submit itself to any jurisdiction. |
| 13 | + */ |
| 14 | + |
| 15 | +const globals = require('globals'); |
| 16 | +const pluginJs = require('@eslint/js'); |
| 17 | +const tseslint = require('typescript-eslint'); |
| 18 | +const jsdoc = require('eslint-plugin-jsdoc'); |
| 19 | +const stylisticTs = require('@stylistic/eslint-plugin-ts'); |
| 20 | +const stylisticJs = require('@stylistic/eslint-plugin-js'); |
| 21 | +const eslintConfigPrettier = require('eslint-config-prettier'); |
| 22 | + |
| 23 | +const licenseHeader = `/** |
| 24 | + * @license |
| 25 | + * Copyright 2019-2020 CERN and copyright holders of ALICE O2. |
| 26 | + * See http://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 27 | + * All rights not expressly granted are reserved. |
| 28 | + * |
| 29 | + * This software is distributed under the terms of the GNU General Public |
| 30 | + * License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 31 | + * |
| 32 | + * In applying this license CERN does not waive the privileges and immunities |
| 33 | + * granted to it by virtue of its status as an Intergovernmental Organization |
| 34 | + * or submit itself to any jurisdiction. |
| 35 | + */`; |
| 36 | + |
| 37 | +const licenseHeaderRule = { |
| 38 | + meta: { |
| 39 | + type: 'layout', |
| 40 | + docs: { |
| 41 | + description: 'Require license header at the top of files', |
| 42 | + category: 'Stylistic Issues', |
| 43 | + }, |
| 44 | + fixable: 'code', |
| 45 | + schema: [], |
| 46 | + }, |
| 47 | + create(context) { |
| 48 | + return { |
| 49 | + Program(node) { |
| 50 | + const sourceCode = context.getSourceCode(); |
| 51 | + const text = sourceCode.getText(); |
| 52 | + |
| 53 | + if (text.includes('@license')) { |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + context.report({ |
| 58 | + node, |
| 59 | + message: 'Missing license header', |
| 60 | + fix(fixer) { |
| 61 | + return fixer.insertTextBefore(node, licenseHeader + '\n\n'); |
| 62 | + }, |
| 63 | + }); |
| 64 | + }, |
| 65 | + }; |
| 66 | + }, |
| 67 | +}; |
| 68 | + |
| 69 | +module.exports = [ |
| 70 | + { |
| 71 | + ignores: [ |
| 72 | + '**/test/', |
| 73 | + '**/tests/', |
| 74 | + '**/node_modules/', |
| 75 | + '**/build/', |
| 76 | + '**/dist/', |
| 77 | + '**/database/data/', |
| 78 | + '**/lib/public/assets/', |
| 79 | + '**/cpp-api-client/', |
| 80 | + '**/tmp/', |
| 81 | + '**/.nyc_output/', |
| 82 | + '**/jest.config.ts', |
| 83 | + '**/package*.json', |
| 84 | + '**/tsconfig*.json', |
| 85 | + '**/eslint.config.js', |
| 86 | + '**/*d.ts', |
| 87 | + ], |
| 88 | + }, |
| 89 | + |
| 90 | + pluginJs.configs.recommended, |
| 91 | + ...tseslint.configs.recommended, |
| 92 | + |
| 93 | + { |
| 94 | + files: ['**/*.{js,ts}'], |
| 95 | + plugins: { |
| 96 | + '@typescript-eslint': tseslint.plugin, |
| 97 | + jsdoc: jsdoc, |
| 98 | + '@stylistic/ts': stylisticTs, |
| 99 | + '@stylistic/js': stylisticJs, |
| 100 | + custom: { |
| 101 | + rules: { |
| 102 | + 'license-header': licenseHeaderRule, |
| 103 | + }, |
| 104 | + }, |
| 105 | + }, |
| 106 | + |
| 107 | + languageOptions: { |
| 108 | + parser: tseslint.parser, |
| 109 | + parserOptions: { |
| 110 | + ecmaVersion: 'latest', |
| 111 | + sourceType: 'commonjs', |
| 112 | + project: ['./tsconfig.json'], |
| 113 | + }, |
| 114 | + globals: { |
| 115 | + ...globals.node, |
| 116 | + ...globals.es2021, |
| 117 | + ...globals.commonjs, |
| 118 | + }, |
| 119 | + }, |
| 120 | + |
| 121 | + settings: { |
| 122 | + jsdoc: { |
| 123 | + mode: 'typescript', |
| 124 | + tagNamePreference: { |
| 125 | + returns: 'return', |
| 126 | + }, |
| 127 | + }, |
| 128 | + }, |
| 129 | + |
| 130 | + rules: { |
| 131 | + // === CUSTOM RULES === |
| 132 | + 'custom/license-header': 'error', |
| 133 | + |
| 134 | + // === TYPESCRIPT SPECIFIC RULES === |
| 135 | + '@typescript-eslint/no-unused-vars': [ |
| 136 | + 'error', |
| 137 | + { |
| 138 | + argsIgnorePattern: '^_', |
| 139 | + varsIgnorePattern: '^_', |
| 140 | + ignoreRestSiblings: true, |
| 141 | + }, |
| 142 | + ], |
| 143 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 144 | + '@typescript-eslint/prefer-nullish-coalescing': 'error', |
| 145 | + '@typescript-eslint/prefer-optional-chain': 'error', |
| 146 | + '@typescript-eslint/no-non-null-assertion': 'warn', |
| 147 | + '@typescript-eslint/consistent-type-imports': 'error', |
| 148 | + |
| 149 | + // === GENERAL CODE QUALITY === |
| 150 | + 'arrow-body-style': ['error', 'as-needed'], |
| 151 | + curly: 'error', |
| 152 | + 'no-console': 'error', |
| 153 | + 'no-implicit-coercion': 'error', |
| 154 | + 'no-return-assign': 'error', |
| 155 | + 'no-var': 'error', |
| 156 | + 'one-var': ['error', 'never'], |
| 157 | + 'prefer-const': 'error', |
| 158 | + 'prefer-destructuring': 'warn', |
| 159 | + 'prefer-template': 'error', |
| 160 | + radix: 'error', |
| 161 | + |
| 162 | + // === COMMENTS AND DOCUMENTATION === |
| 163 | + 'capitalized-comments': ['error', 'always'], |
| 164 | + 'jsdoc/require-description': 'error', |
| 165 | + 'jsdoc/require-returns': 'off', |
| 166 | + 'jsdoc/require-jsdoc': [ |
| 167 | + 'error', |
| 168 | + { |
| 169 | + require: { |
| 170 | + FunctionDeclaration: true, |
| 171 | + MethodDefinition: true, |
| 172 | + ClassDeclaration: true, |
| 173 | + ArrowFunctionExpression: false, |
| 174 | + FunctionExpression: true, |
| 175 | + }, |
| 176 | + }, |
| 177 | + ], |
| 178 | + |
| 179 | + // === TYPESCRIPT STYLISTIC RULES === |
| 180 | + '@stylistic/ts/comma-dangle': ['error', 'always-multiline'], |
| 181 | + '@stylistic/ts/comma-spacing': ['error', { before: false, after: true }], |
| 182 | + '@stylistic/ts/indent': ['error', 2], |
| 183 | + '@stylistic/ts/quotes': ['error', 'single', { avoidEscape: true }], |
| 184 | + '@stylistic/ts/semi': 'error', |
| 185 | + '@stylistic/ts/space-before-blocks': 'error', |
| 186 | + '@stylistic/ts/space-infix-ops': 'error', |
| 187 | + '@stylistic/ts/object-curly-spacing': ['error', 'always'], |
| 188 | + '@stylistic/ts/keyword-spacing': 'error', |
| 189 | + '@stylistic/ts/type-annotation-spacing': 'error', |
| 190 | + '@stylistic/ts/member-delimiter-style': 'error', |
| 191 | + |
| 192 | + // === JAVASCRIPT STYLISTIC RULES === |
| 193 | + '@stylistic/js/array-bracket-spacing': ['error', 'never'], |
| 194 | + '@stylistic/js/brace-style': ['error', '1tbs'], |
| 195 | + '@stylistic/js/no-trailing-spaces': 'error', |
| 196 | + '@stylistic/js/eol-last': ['error', 'always'], |
| 197 | + '@stylistic/js/max-len': ['error', { code: 145 }], |
| 198 | + '@stylistic/js/no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }], |
| 199 | + |
| 200 | + // === DISABLED RULES === |
| 201 | + 'no-magic-numbers': 'off', |
| 202 | + 'sort-keys': 'off', |
| 203 | + 'sort-imports': 'off', |
| 204 | + 'sort-vars': 'off', |
| 205 | + }, |
| 206 | + }, |
| 207 | + { |
| 208 | + files: ['**/*.test.{js,ts}', '**/test/**/*.{js,ts}'], |
| 209 | + languageOptions: { |
| 210 | + globals: { |
| 211 | + ...globals.jest, |
| 212 | + |
| 213 | + describe: 'readonly', |
| 214 | + it: 'readonly', |
| 215 | + expect: 'readonly', |
| 216 | + beforeEach: 'readonly', |
| 217 | + afterEach: 'readonly', |
| 218 | + }, |
| 219 | + }, |
| 220 | + |
| 221 | + rules: { |
| 222 | + 'no-console': 'off', |
| 223 | + 'jsdoc/require-jsdoc': 'off', |
| 224 | + }, |
| 225 | + }, |
| 226 | + eslintConfigPrettier, |
| 227 | +]; |
0 commit comments