Skip to content

Commit

Permalink
feat(nx): convert to eslint flat config (spartan-ng#265)
Browse files Browse the repository at this point in the history
* feat(nx): convert to eslint flat config

* fix(nx): use .cjs extensions for flat config to work

---------

Co-authored-by: Robin Goetz <[email protected]>
  • Loading branch information
benpsnyder and goetzrobin authored Apr 23, 2024
1 parent 694e0e4 commit fbf92e3
Show file tree
Hide file tree
Showing 183 changed files with 2,580 additions and 2,119 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

66 changes: 0 additions & 66 deletions .eslintrc.json

This file was deleted.

4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"eslint.validate": ["json"]
"eslint.validate": ["json"],
"eslint.experimental.useFlatConfig": true,
"eslint.format.enable": true
}
34 changes: 0 additions & 34 deletions apps/app/.eslintrc.json

This file was deleted.

42 changes: 42 additions & 0 deletions apps/app/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { FlatCompat } = require('@eslint/eslintrc');
const baseConfig = require('../../eslint.config.cjs');
const js = require('@eslint/js');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});

module.exports = [
...baseConfig,
...compat
.config({ extends: ['plugin:@nx/angular', 'plugin:@angular-eslint/template/process-inline-templates'] })
.map((config) => ({
...config,
files: ['**/*.ts'],
rules: {
'@angular-eslint/no-host-metadata-property': 0,
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'spartan',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'spartan',
style: 'kebab-case',
},
],
},
})),
...compat.config({ extends: ['plugin:@nx/angular-template'] }).map((config) => ({
...config,
files: ['**/*.html'],
rules: {},
})),
];
6 changes: 3 additions & 3 deletions apps/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"sourceRoot": "apps/app/src",
"tags": [],
"implicitDependencies": [],
"targets": {
"build": {
"dependsOn": ["^build"],
Expand Down Expand Up @@ -77,7 +79,5 @@
},
"dependsOn": ["build"]
}
},
"tags": [],
"implicitDependencies": []
}
}
17 changes: 0 additions & 17 deletions apps/trpc-app-e2e/.eslintrc.json

This file was deleted.

16 changes: 16 additions & 0 deletions apps/trpc-app-e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const baseConfig = require('../../eslint.config.js');

module.exports = [
...baseConfig,
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {},
},
{
files: ['src/plugins/index.js'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'no-undef': 'off',
},
},
];
6 changes: 3 additions & 3 deletions apps/trpc-app-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/trpc-app-e2e/src",
"projectType": "application",
"tags": [],
"implicitDependencies": ["app"],
"targets": {
"vitest": {
"executor": "@nx/vite:test"
Expand All @@ -18,7 +20,5 @@
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
}
},
"tags": [],
"implicitDependencies": ["app"]
}
}
10 changes: 0 additions & 10 deletions apps/ui-storybook-e2e/.eslintrc.json

This file was deleted.

17 changes: 17 additions & 0 deletions apps/ui-storybook-e2e/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { FlatCompat } = require('@eslint/eslintrc');
const baseConfig = require('../../eslint.config.js');
const js = require('@eslint/js');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});

module.exports = [
...baseConfig,
...compat.extends('plugin:cypress/recommended'),
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {},
},
];
6 changes: 3 additions & 3 deletions apps/ui-storybook-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/ui-storybook-e2e/src",
"projectType": "application",
"tags": ["scope:e2e"],
"implicitDependencies": ["ui-storybook"],
"targets": {
"e2e": {
"executor": "@nx/cypress:cypress",
Expand All @@ -21,7 +23,5 @@
"executor": "@nx/eslint:lint",
"outputs": ["{options.outputFile}"]
}
},
"tags": ["scope:e2e"],
"implicitDependencies": ["ui-storybook"]
}
}
69 changes: 69 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { FlatCompat } = require('@eslint/eslintrc');
const nxEslintPlugin = require('@nx/eslint-plugin');
const js = require('@eslint/js');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});

module.exports = [
{ plugins: { '@nx': nxEslintPlugin } },
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {
'@nx/enforce-module-boundaries': [
'error',
{
enforceBuildableLibDependency: true,
allow: [],
depConstraints: [
{
sourceTag: '*',
onlyDependOnLibsWithTags: ['*'],
},
],
},
],
},
},
...compat.config({ extends: ['plugin:@nx/typescript'] }).map((config) => ({
...config,
files: ['**/*.ts', '**/*.tsx'],
rules: {},
})),
...compat.config({ extends: ['plugin:@nx/javascript'] }).map((config) => ({
...config,
files: ['**/*.js', '**/*.jsx'],
rules: {},
})),
...compat.config({ env: { jest: true } }).map((config) => ({
...config,
files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.spec.js', '**/*.spec.jsx'],
rules: {},
})),
...compat.config({ parser: 'jsonc-eslint-parser' }).map((config) => ({
...config,
files: ['**/*.json'],
rules: {
'@nx/dependency-checks': [
'error',
{
buildTargets: ['build'],
checkMissingDependencies: true,
checkObsoleteDependencies: true,
checkVersionMismatches: true,
ignoredDependencies: [
'jest-preset-angular',
'jest-axe',
'@testing-library/jest-dom',
'rxjs',
'@spartan-ng/ui-icon-helm',
'@spartan-ng/ui-button-helm',
'@spartan-ng/ui-avatar-brain',
],
},
],
},
})),
];
25 changes: 0 additions & 25 deletions libs/cli/.eslintrc.json

This file was deleted.

29 changes: 29 additions & 0 deletions libs/cli/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { FlatCompat } = require('@eslint/eslintrc');
const baseConfig = require('../../eslint.config.js');
const js = require('@eslint/js');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});

module.exports = [
...baseConfig,
{
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
rules: {},
},
{
files: ['**/*.ts', '**/*.tsx'],
rules: {},
},
{
files: ['**/*.js', '**/*.jsx'],
rules: {},
},
...compat.config({ parser: 'jsonc-eslint-parser' }).map((config) => ({
...config,
files: ['./package.json', './executors.json'],
rules: { '@nx/nx-plugin-checks': 'error' },
})),
];
Loading

0 comments on commit fbf92e3

Please sign in to comment.