Skip to content

Commit

Permalink
Upgraded dependencies and dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
burtek committed Jan 8, 2024
1 parent 290be8a commit 948421b
Show file tree
Hide file tree
Showing 14 changed files with 1,298 additions and 1,485 deletions.
24 changes: 14 additions & 10 deletions configs/base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// eslint-disable-next-line import/newline-after-import
import ts from '@typescript-eslint/eslint-plugin';
// @ts-expect-error
// eslint-disable-next-line
import tsParser from '@typescript-eslint/parser';
import * as tsParser from '@typescript-eslint/parser';
import { defineFlatConfig } from 'eslint-define-config';
import importPlugin from 'eslint-plugin-import';
import promise from 'eslint-plugin-promise';

import { baseNamingRuleConfig } from './share/naming-config.js';
import { baseNamingRuleConfig } from './share/naming-config';


// eslint-disable-next-line no-warning-comments
Expand Down Expand Up @@ -207,7 +204,7 @@ export function prepareConfig() {
'no-multiple-empty-lines': ['error', { max: 2 }],
'no-negated-condition': 'error',
'no-nested-ternary': 'warn',
'no-new-object': 'error',
'no-object-constructor': 'error',
'no-trailing-spaces': 'error',
'no-whitespace-before-property': 'error',
'object-curly-newline': ['error', { multiline: true }],
Expand Down Expand Up @@ -301,11 +298,11 @@ export function prepareConfig() {
},
{
files: tsFiles,
plugins: { '@typescript-eslint': ts },
// @ts-expect-error
plugins: { '@typescript-eslint': /** @type {import('eslint').ESLint.Plugin} */(ts) },
languageOptions: { parser: tsParser },
rules: {
// @ts-ignore
...ts.configs['eslint-recommended'].overrides[0].rules,
...ts.configs['eslint-recommended'].overrides?.[0].rules,
...importPlugin.configs.typescript.rules,

'@typescript-eslint/adjacent-overload-signatures': 'error',
Expand Down Expand Up @@ -387,6 +384,8 @@ export function prepareConfig() {
'@typescript-eslint/no-unsafe-enum-comparison': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unsafe-unary-minus': 'error',
'@typescript-eslint/no-useless-template-literals': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-enum-initializers': 'error',
'@typescript-eslint/prefer-for-of': 'error',
Expand All @@ -406,7 +405,10 @@ export function prepareConfig() {
allowNumber: true,
allowNullish: true
}],
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/switch-exhaustiveness-check': ['error', {
allowDefaultCaseForExhaustiveSwitch: false,
requireDefaultForNonUnion: true
}],
'@typescript-eslint/type-annotation-spacing': 'error',

'block-spacing': 'off',
Expand Down Expand Up @@ -437,6 +439,7 @@ export function prepareConfig() {
'no-use-before-define': 'off',
'no-useless-constructor': 'off',
'quotes': 'off',
'prefer-destructuring': 'off',
'require-await': 'off',
'semi': 'off',
'space-before-blocks': 'off',
Expand Down Expand Up @@ -505,6 +508,7 @@ export function prepareConfig() {
'@typescript-eslint/no-useless-empty-export': 'error',
'@typescript-eslint/parameter-properties': ['error', { prefer: 'parameter-property' }],
'@typescript-eslint/quotes': ['error', 'single'],
'@typescript-eslint/prefer-destructuring': 'error',
'@typescript-eslint/require-await': 'error',
'@typescript-eslint/return-await': ['error', 'always'],
'@typescript-eslint/semi': 'error',
Expand Down
1 change: 1 addition & 0 deletions configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { prepareConfig as node } from './node.js';
import { prepareConfig as react } from './react.js';
import { prepareConfig as testingLibrary } from './testing-library.js';


/**
* @template T
* @typedef {Promise<T> | T} MaybePromise
Expand Down
4 changes: 1 addition & 3 deletions configs/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const mockFiles = '**/__mocks__/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}';
const tsTestFiles = '**/*.test.{ts,cts,mts,tsx}';
const tsMockFiles = '**/__mocks__/**/*.{ts,cts,mts,tsx}';

// /** @typedef {Partial<import('eslint-define-config/src/rules/jsonc/index.js').JsoncRules>} JsoncRules */
// /** @typedef {Partial<import('eslint-define-config/src/rules/eslint/index.js').EslintRules>} EslintRules */

/**
* @param {Object} [config]
* @param {'jest' | 'vitest'} [config.mode]
Expand Down Expand Up @@ -66,6 +63,7 @@ export function prepareConfig({ mode = 'jest' } = {}) {

'jest/consistent-test-it': 'error',
'jest/no-conditional-in-test': 'error',
'jest/no-confusing-set-time': 'error',
'jest/no-duplicate-hooks': 'error',
'jest/no-test-return-statement': 'error',
'jest/prefer-each': 'error',
Expand Down
14 changes: 7 additions & 7 deletions configs/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { defineFlatConfig } from 'eslint-define-config';
import * as jsonc from 'eslint-plugin-jsonc';
import jsonParser from 'jsonc-eslint-parser';

/** @typedef {Partial<import('eslint-define-config/src/rules/jsonc/index.js').JsoncRules>} JsoncRules */
/** @typedef {Partial<import('eslint-define-config/src/rules/eslint/index.js').EslintRules>} EslintRules */

/** @typedef {Partial<import('eslint-define-config').Rules>} Rules */

const wellKnownJsonc = [
'**/tsconfig.json',
Expand All @@ -26,28 +26,28 @@ export function prepareConfig({
{
files: ['**/*.{json,jsonc,json5}', ...additionalFilesJson, ...additionalFilesJson5, ...additionalFilesJsonc],
plugins: /** @type {any} */({ jsonc }),
languageOptions: { parser: /** @type {any} */(jsonParser) },
rules: /** @type {EslintRules} */(jsonc.configs.base.overrides[0].rules)
languageOptions: { parser: jsonParser },
rules: /** @type {Rules} */(jsonc.configs.base.overrides[0].rules)
},
{
files: ['**/*.json', ...additionalFilesJson],
ignores: [...wellKnownJsonc],
rules: {
.../** @type {JsoncRules} */(jsonc.configs['recommended-with-json'].rules),
.../** @type {Rules} */(jsonc.configs['recommended-with-json'].rules),
'jsonc/indent': ['error', 2]
}
},
{
files: ['**/*.jsonc', ...wellKnownJsonc, ...additionalFilesJsonc],
rules: {
.../** @type {JsoncRules} */(jsonc.configs['recommended-with-jsonc'].rules),
.../** @type {Rules} */(jsonc.configs['recommended-with-jsonc'].rules),
'jsonc/indent': ['error', 2]
}
},
{
files: ['**/*.json5', ...additionalFilesJson5],
rules: {
.../** @type {JsoncRules} */(jsonc.configs['recommended-with-json5'].rules),
.../** @type {Rules} */(jsonc.configs['recommended-with-json5'].rules),
'jsonc/indent': ['error', 2]
}
}
Expand Down
20 changes: 3 additions & 17 deletions configs/node.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import { defineFlatConfig } from 'eslint-define-config';
import nModule from 'eslint-plugin-n/configs/recommended-module.js';
import nScript from 'eslint-plugin-n/configs/recommended-script.js';
import nPlugin from 'eslint-plugin-n';
import nodeSecurity from 'eslint-plugin-security-node';
import globals from 'globals';


/**
* @param {Object} [config]
* @param {'module' | 'script'} [config.mode]
*/
export function prepareConfig({ mode = 'module' } = {}) {
const isModule = mode === 'module';

export function prepareConfig() {
return defineFlatConfig([
{
files: [isModule ? '**/*.{cjs,cts}' : '**/*.{js,cjs,ts,cts}'],
...nScript
},
{
files: [isModule ? '**/*.{js,mjs,ts,mts}' : '**/*.{mjs,mts}'],
...nModule
},
...nPlugin.configs['flat/mixed-esm-and-cjs'].map(c => ({ ...c, files: c.files.flatMap(f => [f, f.replace('.js', '.ts')]) })),
{
files: ['**/*.{js,cjs,mjs,ts,cts,mts}'],
languageOptions: {
Expand Down
42 changes: 22 additions & 20 deletions configs/react.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import next from '@next/eslint-plugin-next';
import { defineFlatConfig } from 'eslint-define-config';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import reactConfigJsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';
import reactConfigRecommended from 'eslint-plugin-react/configs/recommended.js';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import globals from 'globals';

import { reactNamingRuleConfig } from './share/naming-config.js';
import { reactNamingRuleConfig } from './share/naming-config';


const linkComponents = [
Expand Down Expand Up @@ -36,30 +35,22 @@ export function prepareConfig({ a11y = false, nextjs = false } = {}) {
const baseConfig = defineFlatConfig([
{
files,
...reactConfigRecommended
},
{
files,
...reactConfigJsxRuntime
},
{
files,
plugins: { react },
languageOptions: {
globals: {
...globals.serviceworker,
...globals.browser
}
parserOptions: {
ecmaFeatures: { jsx: true },
jsxPragma: null
},
globals: globals.browser
},
plugins: { 'react-hooks': reactHooks },
rules: reactHooks.configs.recommended.rules
},
{
files,
settings: {
react: { version: 'detect' },
linkComponents
},
rules: {
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,

'jsx-quotes': ['error', 'prefer-double'],

'react/button-has-type': 'warn',
Expand Down Expand Up @@ -146,6 +137,17 @@ export function prepareConfig({ a11y = false, nextjs = false } = {}) {
'react/void-dom-elements-no-children': 'error'
}
},
{
files,
languageOptions: {
globals: {
...globals.serviceworker,
...globals.browser
}
},
plugins: { 'react-hooks': reactHooks },
rules: reactHooks.configs.recommended.rules
},
{
files: tsFiles,
rules: { '@typescript-eslint/naming-convention': /** @type {any} */(['error']).concat(reactNamingRuleConfig) }
Expand Down
29 changes: 12 additions & 17 deletions configs/share/naming-config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
/**
* @type {import("eslint-define-config/src/rules/typescript-eslint/naming-convention.js").NamingConventionOption}
*/
/** @type {import('./naming-convention-types').Selector[]} */
export const baseNamingRuleConfig = [
{
// default
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid'
},
{
// const global variables can be UPPER_CASE
selector: 'variable',
Expand Down Expand Up @@ -54,14 +45,18 @@ export const baseNamingRuleConfig = [
],
format: null,
modifiers: ['requiresQuotes']
}
},
{
// default
selector: 'default',
format: ['camelCase'],
leadingUnderscore: 'forbid',
trailingUnderscore: 'forbid'
},
];

/**
* @type {import("eslint-define-config/src/rules/typescript-eslint/naming-convention.js").NamingConventionOption}
*/
export const reactNamingRuleConfig = [
...baseNamingRuleConfig,
/** @type {import('./naming-convention-types').Selector[]} */
export const reactNamingRuleConfig = baseNamingRuleConfig.slice().splice(-1, 0,
{
// React Components
selector: 'variable',
Expand Down Expand Up @@ -93,4 +88,4 @@ export const reactNamingRuleConfig = [
filter: '^use',
format: ['camelCase']
}
];
);
90 changes: 90 additions & 0 deletions configs/share/naming-convention-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
type PredefinedFormatsString =
| 'camelCase'
| 'strictCamelCase'
| 'PascalCase'
| 'StrictPascalCase'
| 'snake_case'
| 'UPPER_CASE';

type UnderscoreOptionsString =
| 'forbid'
| 'allow'
| 'require'
| 'requireDouble'
| 'allowDouble'
| 'allowSingleOrDouble';

type SelectorsString =
| 'variable'
| 'function'
| 'parameter'
| 'parameterProperty'
| 'accessor'
| 'enumMember'
| 'classMethod'
| 'objectLiteralMethod'
| 'typeMethod'
| 'classProperty'
| 'objectLiteralProperty'
| 'typeProperty'
| 'class'
| 'interface'
| 'typeAlias'
| 'enum'
| 'typeParameter'
| 'import';

type MetaSelectorsString =
| 'default'
| 'variableLike'
| 'memberLike'
| 'typeLike'
| 'method'
| 'property';
type IndividualAndMetaSelectorsString = MetaSelectorsString | SelectorsString;

type ModifiersString =
| 'const'
| 'readonly'
| 'static'
| 'public'
| 'protected'
| 'private'
| '#private'
| 'abstract'
| 'destructured'
| 'global'
| 'exported'
| 'unused'
| 'requiresQuotes'
| 'override'
| 'async'
| 'default'
| 'namespace';

type TypeModifiersString =
| 'boolean'
| 'string'
| 'number'
| 'function'
| 'array';

interface MatchRegex {
regex: string;
match: boolean;
}

export interface Selector {
// format options
format: PredefinedFormatsString[] | null;
custom?: MatchRegex;
leadingUnderscore?: UnderscoreOptionsString;
trailingUnderscore?: UnderscoreOptionsString;
prefix?: string[];
suffix?: string[];
// selector options
selector: IndividualAndMetaSelectorsString | IndividualAndMetaSelectorsString[];
modifiers?: ModifiersString[];
types?: TypeModifiersString[];
filter?: MatchRegex | string;
}
Loading

0 comments on commit 948421b

Please sign in to comment.