UNPKG

@gmjs/eslint-config

Version:
134 lines (133 loc) 4.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getEsLintConfigs = getEsLintConfigs; const tslib_1 = require("tslib"); const globals_1 = tslib_1.__importDefault(require("globals")); const js_1 = tslib_1.__importDefault(require("@eslint/js")); const typescript_eslint_1 = tslib_1.__importDefault(require("typescript-eslint")); const eslint_plugin_unicorn_1 = tslib_1.__importDefault(require("eslint-plugin-unicorn")); const eslint_plugin_n_1 = tslib_1.__importDefault(require("eslint-plugin-n")); const eslint_config_prettier_1 = tslib_1.__importDefault(require("eslint-config-prettier")); function getEsLintConfigs(options) { const { projectType } = options; const isReact = projectType === 'react'; const isNode = projectType === 'node'; const isBrowser = projectType === 'browser'; const isStorybook = isReact && options.storybook; return [ { name: 'general', linterOptions: { reportUnusedDisableDirectives: 'error', }, }, js_1.default.configs.recommended, ...typescript_eslint_1.default.configs.recommended, { name: 'js/ts overrides', files: ['**/*.{js,jsx,ts,tsx}'], rules: { 'no-fallthrough': 'off', }, }, { name: 'ts-only overrides', files: ['**/*.{ts,tsx}'], rules: { '@typescript-eslint/explicit-function-return-type': 'error', '@typescript-eslint/explicit-member-accessibility': 'error', '@typescript-eslint/explicit-module-boundary-types': 'error', '@typescript-eslint/no-unused-vars': [ 'warn', { argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_', ignoreRestSiblings: true, }, ], }, }, eslint_plugin_unicorn_1.default.configs['flat/recommended'], { name: 'unicorn overrides', files: ['**/*.{js,jsx,ts,tsx}'], rules: { 'unicorn/consistent-function-scoping': 'off', 'unicorn/import-style': [ 'error', { styles: { path: { named: true, }, 'node:path': { named: true, }, }, }, ], 'unicorn/prefer-module': 'off', 'unicorn/prefer-top-level-await': 'off', 'unicorn/prevent-abbreviations': 'off', 'unicorn/no-array-reduce': 'off', 'unicorn/no-negated-condition': 'off', 'unicorn/no-useless-undefined': 'off', 'unicorn/filename-case': 'off', }, }, { name: 'tests', files: ['**/*.{spec,test}.{ts,tsx,js,jsx}'], rules: { 'unicorn/consistent-function-scoping': 'off', }, }, ...(isNode ? getNodeConfigs() : []), ...(isBrowser ? getBrowserConfigs() : []), ...(isReact ? getReactConfigs(isStorybook) : []), eslint_config_prettier_1.default, ]; } function getNodeConfigs() { return [ { name: 'node main', languageOptions: { globals: { ...globals_1.default.node, }, }, }, eslint_plugin_n_1.default.configs['flat/recommended'], { name: 'node ts-only overrides', files: ['**/*.{ts,tsx}'], rules: { 'n/hashbang': 'off', 'n/no-missing-import': 'off', 'n/no-unpublished-import': 'off', 'n/no-unsupported-features/es-syntax': 'off', }, }, ]; } function getBrowserConfigs() { return [ { name: 'browser main', languageOptions: { globals: { ...globals_1.default.browser, }, }, }, ]; } function getReactConfigs(isStorybook) { return [ ...(isStorybook ? getStorybookConfigs() : []), ]; } function getStorybookConfigs() { return []; }