|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const path = require('node:path') |
| 4 | + |
| 5 | +const { includeIgnoreFile } = require('@eslint/compat') |
| 6 | +const js = require('@eslint/js') |
| 7 | +const importXPlugin = require('eslint-plugin-import-x') |
| 8 | +const nodePlugin = require('eslint-plugin-n') |
| 9 | +const sortDestructureKeysPlugin = require('eslint-plugin-sort-destructure-keys') |
| 10 | +const unicornPlugin = require('eslint-plugin-unicorn') |
| 11 | + |
| 12 | +const constants = require('@socketsecurity/registry/lib/constants') |
| 13 | +const { GIT_IGNORE, PRETTIER_IGNORE } = constants |
| 14 | + |
| 15 | +const rootPath = __dirname |
| 16 | + |
| 17 | +const gitignorePath = path.resolve(rootPath, GIT_IGNORE) |
| 18 | +const prettierignorePath = path.resolve(rootPath, PRETTIER_IGNORE) |
| 19 | + |
| 20 | +module.exports = [ |
| 21 | + includeIgnoreFile(gitignorePath), |
| 22 | + includeIgnoreFile(prettierignorePath), |
| 23 | + { |
| 24 | + files: ['**/*.{c,}js'], |
| 25 | + ...importXPlugin.flatConfigs.recommended, |
| 26 | + languageOptions: { |
| 27 | + ...importXPlugin.flatConfigs.recommended.languageOptions, |
| 28 | + ecmaVersion: 'latest', |
| 29 | + sourceType: 'script' |
| 30 | + }, |
| 31 | + rules: { |
| 32 | + ...importXPlugin.flatConfigs.recommended.rules, |
| 33 | + 'import-x/no-named-as-default-member': 'off', |
| 34 | + 'import-x/no-unresolved': ['error', { commonjs: true }], |
| 35 | + 'import-x/order': [ |
| 36 | + 'warn', |
| 37 | + { |
| 38 | + groups: [ |
| 39 | + 'builtin', |
| 40 | + 'external', |
| 41 | + 'internal', |
| 42 | + ['parent', 'sibling', 'index'], |
| 43 | + 'type' |
| 44 | + ], |
| 45 | + pathGroups: [ |
| 46 | + { |
| 47 | + pattern: '@socket{registry,security}/**', |
| 48 | + group: 'internal' |
| 49 | + } |
| 50 | + ], |
| 51 | + pathGroupsExcludedImportTypes: ['type'], |
| 52 | + 'newlines-between': 'always', |
| 53 | + alphabetize: { |
| 54 | + order: 'asc' |
| 55 | + } |
| 56 | + } |
| 57 | + ] |
| 58 | + } |
| 59 | + }, |
| 60 | + { |
| 61 | + files: ['scripts/**/*.js', 'test/**/*.cjs'], |
| 62 | + ...nodePlugin.configs['flat/recommended-script'] |
| 63 | + }, |
| 64 | + { |
| 65 | + files: ['scripts/**/*.js', 'test/**/*.cjs'], |
| 66 | + plugins: { |
| 67 | + 'sort-destructure-keys': sortDestructureKeysPlugin, |
| 68 | + unicorn: unicornPlugin |
| 69 | + }, |
| 70 | + rules: { |
| 71 | + ...js.configs.recommended.rules, |
| 72 | + 'n/exports-style': ['error', 'module.exports'], |
| 73 | + // The n/no-unpublished-bin rule does does not support non-trivial glob |
| 74 | + // patterns used in package.json "files" fields. In those cases we simplify |
| 75 | + // the glob patterns used. |
| 76 | + 'n/no-unpublished-bin': ['error'], |
| 77 | + 'n/no-unsupported-features/es-builtins': ['error'], |
| 78 | + 'n/no-unsupported-features/es-syntax': ['error'], |
| 79 | + 'n/no-unsupported-features/node-builtins': [ |
| 80 | + 'error', |
| 81 | + { |
| 82 | + ignores: ['test', 'test.describe'], |
| 83 | + // Lazily access constants.maintainedNodeVersions. |
| 84 | + version: constants.maintainedNodeVersions.previous |
| 85 | + } |
| 86 | + ], |
| 87 | + 'n/prefer-node-protocol': ['error'], |
| 88 | + 'no-await-in-loop': ['error'], |
| 89 | + 'no-control-regex': ['error'], |
| 90 | + 'no-empty': ['error', { allowEmptyCatch: true }], |
| 91 | + 'no-new': ['error'], |
| 92 | + 'no-proto': ['error'], |
| 93 | + 'no-unused-vars': [ |
| 94 | + 'error', |
| 95 | + { argsIgnorePattern: '^_|^this$', ignoreRestSiblings: true } |
| 96 | + ], |
| 97 | + 'no-warning-comments': ['warn', { terms: ['fixme'] }], |
| 98 | + 'sort-destructure-keys/sort-destructure-keys': ['error'], |
| 99 | + 'sort-imports': ['error', { ignoreDeclarationSort: true }], |
| 100 | + 'unicorn/consistent-function-scoping': ['error'] |
| 101 | + } |
| 102 | + } |
| 103 | +] |
0 commit comments