Skip to content

Commit

Permalink
chore: upgrade eslint and create new config for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Haoxin Yang authored and fengtianze committed Jul 31, 2024
1 parent 9721908 commit a9fe415
Show file tree
Hide file tree
Showing 7 changed files with 1,090 additions and 2,344 deletions.
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

58 changes: 0 additions & 58 deletions .eslintrc

This file was deleted.

34 changes: 29 additions & 5 deletions angular.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"cli": {
"analytics": false
"analytics": false,
"schematicCollections": [
"@angular-eslint/schematics"
]
},
"version": 1,
"newProjectRoot": "projects",
Expand All @@ -28,7 +31,9 @@
"main": "",
"tsConfig": "tsconfig.json",
"inlineStyleLanguage": "scss",
"styles": ["src/theme/style.scss"]
"styles": [
"src/theme/style.scss"
]
},
"configurations": {
"production": {
Expand Down Expand Up @@ -63,7 +68,12 @@
"configDir": ".storybook",
"browserTarget": "storybook:build",
"compodoc": true,
"compodocArgs": ["-e", "json", "-d", "."],
"compodocArgs": [
"-e",
"json",
"-d",
"."
],
"port": 6006
}
},
Expand All @@ -73,9 +83,23 @@
"configDir": ".storybook",
"browserTarget": "storybook:build",
"compodoc": true,
"compodocArgs": ["-e", "json", "-d", "."],
"compodocArgs": [
"-e",
"json",
"-d",
"."
],
"outputDir": "dist",
"enableProdMode": false // FIXME: https://github.com/storybookjs/storybook/issues/23534
"enableProdMode": false
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"stories/**/*.ts",
"stories/**/*.html"
]
}
}
}
Expand Down
224 changes: 224 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
import js from '@eslint/js';
import tsEslint from 'typescript-eslint';
import angular from 'angular-eslint';
import jestEslint from 'eslint-plugin-jest';
import unicornEslint from 'eslint-plugin-unicorn';
import sonarEslint from 'eslint-plugin-sonarjs';
import { fileURLToPath } from 'url';
import path from 'path';

import { fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});

/**
* @param {string} name the pugin name
* @param {string} alias the plugin alias
* @returns {import("eslint").ESLint.Plugin}
*/
function legacyPlugin(name, alias = name) {
const plugin = compat.plugins(name)[0]?.plugins?.[alias];

if (!plugin) {
throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`);
}

return fixupPluginRules(plugin);
}

export default tsEslint.config(
{
ignores: [
'coverage',
'dist',
'release',
'CHANGELOG.md',
'.angular',
'!.*.js',
'!.storybook',
'documentation.json',
],
},
sonarEslint.configs.recommended,
{
...unicornEslint.configs['flat/recommended'],
rules: {
'unicorn/catch-error-name': [
2,
{
name: 'error',
ignore: ['^e(rr)?$'],
},
],
'unicorn/consistent-function-scoping': 0,
'unicorn/filename-case': [
2,
{
cases: {
kebabCase: true,
pascalCase: true,
},
// ignore UPPER_CASE markdown or yaml filenames
ignore: [/^[A-Z](([\dA-Z]+_)*[\dA-Z]+)?\.(mdx?|ya?ml)$/],
},
],
'unicorn/no-array-reduce': 0,
'unicorn/no-null': 0,
'unicorn/no-unreadable-array-destructuring': 0, // conflict with `no-unused-vars`
'unicorn/prefer-module': 0,
'unicorn/prefer-object-from-entries': 0,
'unicorn/prevent-abbreviations': 0,
'@angular-eslint/template/no-negated-async': 0,
'@typescript-eslint/member-ordering': 0,
'@typescript-eslint/naming-convention': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-floating-promises': 0,
'@typescript-eslint/no-magic-numbers': 0,
'@typescript-eslint/no-type-alias': 0,
'@typescript-eslint/no-unnecessary-condition': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/prefer-ts-expect-error': 0,
'@typescript-eslint/restrict-plus-operands': 0,
'@typescript-eslint/sort-type-union-intersection-members': 0,
'@typescript-eslint/unbound-method': 0,
'accessor-pairs': 0,
'no-magic-numbers': 0,
'no-negated-condition': 0, // not auto-fixable
'promise/always-return': 0,
'promise/catch-or-return': 0,
'unicorn/explicit-length-check': 0,
'unicorn/no-array-for-each': 0,
'unicorn/no-fn-reference-in-iterator': 0,
'unicorn/prefer-number-properties': 0,
'unicorn/prefer-prototype-methods': 0,
'unicorn/prefer-spread': 0,
},
},
{
files: ['**/*.ts'],
extends: [
js.configs.recommended,
...tsEslint.configs.recommended,
...tsEslint.configs.stylistic,
...angular.configs.tsRecommended,
],

ignores: ['**/*.spec.ts', '**/stories/**/*.ts'],
processor: angular.processInlineTemplates,
languageOptions: {
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
requireConfigFile: false,
},
},
rules: {
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: ['aui'],
style: 'kebab-case',
},
],

'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: ['aui'],
style: 'camelCase',
},
],

'unicorn/prefer-event-target': 'off',

'@typescript-eslint/consistent-generic-constructors': 0,
'@typescript-eslint/no-unused-expressions': 0,
'@typescript-eslint/no-explicit-any': 0,
'@angular-eslint/no-output-native': 0,
'@angular-eslint/no-inputs-metadata-property': 'off',
'@angular-eslint/no-output-native': 'off',
'@angular-eslint/no-input-rename': 'off',
'@angular-eslint/no-output-rename': 'off',
'@angular-eslint/no-host-metadata-property': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'markup/markup': 'off',
'regexp/strict': 'off',
'no-empty': [
2,
{
allowEmptyCatch: true,
},
],
'no-empty-function': 0,
'@typescript-eslint/consistent-indexed-object-style': 0,
'@typescript-eslint/array-type': [
2,
{
default: 'array-simple',
},
],
'@typescript-eslint/no-unused-vars': [
2,
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
},
},

{
files: ['**/*.spec.ts'],
extends: [
js.configs.recommended,
...tsEslint.configs.recommended,
...tsEslint.configs.stylistic,
...angular.configs.tsRecommended,
],
...jestEslint.configs['flat/recommended'],
rules: {
'@angular-eslint/prefer-on-push-component-change-detection': 'off',
'@typescript-eslint/no-extraneous-class': 'off',
'jest/expect-expect': 'off',
'jest/no-export': 'off',
'sonarjs/no-duplicate-string': 'off',

'n/no-extraneous-import': 0,
'n/no-extraneous-require': 0,
'n/no-unsupported-features/es-builtins': 0,
'jest/no-conditional-expect': 'error',
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-empty-object-type': 0,
'@typescript-eslint/no-unused-vars': [
2,
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/array-type': [
2,
{
default: 'array-simple',
},
],
},
},
...compat.extends('plugin:import/typescript'),
{
plugins: {
import: legacyPlugin('eslint-plugin-import', 'import'),
},
},
);
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
},
"devDependencies": {
"@1stg/commitlint-config": "^3.2.0",
"@1stg/eslint-config": "^8.0.0",
"@1stg/lint-staged": "^4.0.0",
"@1stg/remark-preset": "^2.0.0",
"@1stg/simple-git-hooks": "^0.2.3",
Expand All @@ -71,6 +70,9 @@
"@changesets/cli": "^2.26.2",
"@commitlint/cli": "^17.7.1",
"@compodoc/compodoc": "^1.1.25",
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
"@storybook/addon-essentials": "^8.2.1",
"@storybook/addon-interactions": "^8.2.1",
"@storybook/addon-links": "^8.2.1",
Expand All @@ -80,9 +82,15 @@
"@types/file-saver": "^2.0.5",
"@types/jest": "29.5.12",
"@types/node": "^20.5.7",
"angular-eslint": "18.1.0",
"chroma-js": "^2.4.2",
"dayjs": "^1.11.11",
"eslint": "^8.48.0",
"eslint": "^9.6.0",
"eslint-formatter-friendly": "^7.0.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-unicorn": "^54.0.0",
"file-saver": "^2.0.5",
"gulp": "^5.0.0",
"gulp-dart-sass": "^1.1.0",
Expand All @@ -104,6 +112,7 @@
"ts-jest": "29.2.0",
"ts-node": "^10.9.2",
"typescript": "~5.4.0",
"typescript-eslint": "7.16.1",
"yarn-deduplicate": "^6.0.2",
"zone.js": "^0.14.7"
},
Expand Down
Loading

0 comments on commit a9fe415

Please sign in to comment.