Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate formatting to eslint v9 #247

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .eslintrc.format.js

This file was deleted.

9 changes: 4 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import tseslint from 'typescript-eslint';
import {cloudflightTypescriptConfig} from '@cloudflight/eslint-plugin-typescript';
import {includeIgnoreFile} from '@eslint/compat';
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';
import tseslint from 'typescript-eslint';

const filename = fileURLToPath(import.meta.url);
const directory = dirname(filename);
Expand All @@ -18,16 +18,15 @@ export default tseslint.config(
'packages/eslint-plugin-typescript/src/configs/index.ts',
'packages/eslint-plugin-typescript/src/configs/json.ts',
'packages/eslint-plugin-typescript/src/configs/package.ts',
'packages/eslint-plugin-typescript/src/configs/format.ts',
'packages/eslint-plugin-typescript/src/configs/rxjs.ts',
'packages/eslint-plugin-typescript/src/rules/package/*',
'packages/eslint-plugin-typescript/src/rules/ts-config/*',
'packages/eslint-plugin-typescript/src/rules/typescript/*.spec.ts',
'scripts/*',
'.eslintrc.format.js',
'eslint.config.mjs',
'eslint.format.mjs',
'jest.config*.ts',
]
],
},
...cloudflightTypescriptConfig,
{
Expand Down
14 changes: 14 additions & 0 deletions eslint.format.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {cloudflightTypescriptFormatConfig} from '@cloudflight/eslint-plugin-typescript';
import {includeIgnoreFile} from '@eslint/compat';
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
import tseslint from 'typescript-eslint';

const filename = fileURLToPath(import.meta.url);
const directory = dirname(filename);
const gitignorePath = resolve(directory, '.gitignore');

export default tseslint.config(
includeIgnoreFile(gitignorePath),
...cloudflightTypescriptFormatConfig,
);
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin",
"version": "1.0.0-rc9",
"version": "1.0.0-rc10",
"private": true,
"volta": {
"node": "20.12.2",
Expand All @@ -16,7 +16,7 @@
"description": "",
"scripts": {
"build": "yarn workspaces foreach -pA --topological-dev run build-package",
"lint": "eslint .",
"lint": "eslint . && eslint -c eslint.format.mjs .",
"test": "yarn workspaces foreach -pA run test-package",
"postinstall": "husky",
"publish-workspaces": "node ./scripts/prepare.js && yarn workspaces foreach -A --no-private npm publish"
Expand All @@ -30,6 +30,7 @@
"devDependencies": {
"@eslint/compat": "1.2.0",
"@eslint/js": "9.11.1",
"@stylistic/eslint-plugin": "2.9.0",
"@types/eslint": "9.6.1",
"@types/eslint__js": "8.42.3",
"@types/estree": "1.0.6",
Expand All @@ -47,6 +48,7 @@
"eslint-plugin-jsx-a11y": "6.10.0",
"eslint-plugin-n": "17.10.3",
"eslint-plugin-no-unsanitized": "4.1.2",
"eslint-plugin-perfectionist": "3.9.0",
"eslint-plugin-react": "7.37.1",
"eslint-plugin-react-hooks": "5.0.0",
"eslint-plugin-rxjs": "5.0.3",
Expand All @@ -61,7 +63,7 @@
"typescript-eslint": "8.8.0"
},
"lint-staged": {
"*.js": "echo 'Not Implemented'",
"*.ts": "echo 'Not Implemented'"
"*.js": "eslint -c eslint.format.mjs --fix",
"*.ts": "eslint -c eslint.format.mjs --fix"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-angular",
"version": "1.0.0-rc9",
"version": "1.0.0-rc10",
"description": "Cloudflight eslint-plugin & eslint-config for angular",
"volta": {
"extends": "../../package.json"
Expand Down
15 changes: 8 additions & 7 deletions packages/eslint-plugin-angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import tseslint from 'typescript-eslint';
import angular from 'angular-eslint';
import {cloudflightTypescriptConfig} from '@cloudflight/eslint-plugin-typescript';
import {eslintRules} from './configs/eslint';
import {typescriptEslintRules} from './configs/typescript-eslint';
import angular from 'angular-eslint';
import tseslint from 'typescript-eslint';

import {angularEslintRules} from './configs/angular-eslint';
import {angularTemplateEslintRules} from './configs/angular-eslint-template';
import {eslintRules} from './configs/eslint';
import {typescriptEslintRules} from './configs/typescript-eslint';

export const cloudflightAngularTypescriptConfig = tseslint.config(
...cloudflightTypescriptConfig,
Expand All @@ -19,7 +20,7 @@ export const cloudflightAngularTypescriptConfig = tseslint.config(
...eslintRules,
...typescriptEslintRules,
...angularEslintRules,
}
},
},
);

Expand All @@ -35,8 +36,8 @@ export const cloudflightAngularTemplateConfig = tseslint.config(
...angularTemplateEslintRules,
// todo: this should be its own config
// ...formatAngularTemplateEslintRules,
}
}
},
},
);

export const cloudflightAngularConfig = tseslint.config(
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-node",
"version": "1.0.0-rc9",
"version": "1.0.0-rc10",
"description": "Cloudflight eslint-plugin & eslint-config for node",
"volta": {
"extends": "../../package.json"
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-plugin-node/src/configs/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function warningEntryToError(value: TSESLint.Linter.RuleEntry): TSESLint.Linter.
function warningLevelToError(level: TSESLint.Linter.RuleLevel): TSESLint.Linter.RuleLevel {
if (level === 'warn') {
return 'error';
} else if (level === 1) {
}
else if (level === 1) {
return 'error';
}

Expand Down
13 changes: 7 additions & 6 deletions packages/eslint-plugin-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import tseslint from 'typescript-eslint';
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';
import {cloudflightTypescriptConfig} from '@cloudflight/eslint-plugin-typescript';
import pluginNode from 'eslint-plugin-n';
import nounsanitized from 'eslint-plugin-no-unsanitized';
import pluginSecurity from 'eslint-plugin-security';
import pluginNode from 'eslint-plugin-n';
import {securityRules} from './configs/security';
import {nodeRules} from './configs/node';
import tseslint from 'typescript-eslint';

import {importEslintRules} from './configs/import';
import {nodeRules} from './configs/node';
import {securityRules} from './configs/security';

export const cloudflightNodeConfig = tseslint.config(
...cloudflightTypescriptConfig,
Expand All @@ -21,6 +22,6 @@ export const cloudflightNodeConfig = tseslint.config(
...nodeRules,
...securityRules,
...importEslintRules,
}
},
},
);
2 changes: 1 addition & 1 deletion packages/eslint-plugin-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-react",
"version": "1.0.0-rc9",
"version": "1.0.0-rc10",
"description": "Cloudflight eslint-plugin & eslint-config for React",
"volta": {
"extends": "../../package.json"
Expand Down
12 changes: 7 additions & 5 deletions packages/eslint-plugin-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import tseslint from 'typescript-eslint';
import type {TSESLint} from '@typescript-eslint/utils';

import {
cloudflightTypescriptBaseConfig,
cloudflightTypescriptConfig, cloudflightTypescriptDisableTypeCheckedConfig,
cloudflightTypescriptImportConfig
cloudflightTypescriptImportConfig,
} from '@cloudflight/eslint-plugin-typescript';
import type {TSESLint} from '@typescript-eslint/utils';
import * as tsParser from '@typescript-eslint/parser';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import tseslint from 'typescript-eslint';
// see https://github.com/jsx-eslint/eslint-plugin-react/issues/3838
// eslint-disable-next-line import-x/default
import react from 'eslint-plugin-react';
import pluginReactHooks from 'eslint-plugin-react-hooks';
import jsxA11y from 'eslint-plugin-jsx-a11y';

import {reactRules} from './configs/react';

export const cloudflightReactConfig = tseslint.config(
Expand Down Expand Up @@ -51,7 +53,7 @@ export const cloudflightReactConfig = tseslint.config(
rules: {
...pluginReactHooks.configs.recommended.rules,
...reactRules,
}
},
},
{
files: ['**/*.{js,jsx,mjs,cjs}'],
Expand Down
34 changes: 18 additions & 16 deletions packages/eslint-plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,26 @@ In your `package.json` add the following:
}
```

Create a new file called `.eslintrc.format.js` and add the following:
Create a new file called `eslint.format.mjs` and add the following:

```
require('@rushstack/eslint-patch/modern-module-resolution');

module.exports = {
root: true,
plugins: ['@cloudflight/typescript'],
extends: ['plugin:@cloudflight/typescript/formatting'],
ignorePatterns: ['jest.config*.ts'],
env: {
es6: true,
node: true,
},
};
```ts
import tseslint from 'typescript-eslint';
import {includeIgnoreFile} from '@eslint/compat';
import {dirname, resolve} from 'node:path';
import {fileURLToPath} from 'node:url';
import {cloudflightTypescriptFormatConfig} from '@cloudflight/eslint-plugin-typescript';

const filename = fileURLToPath(import.meta.url);
const directory = dirname(filename);
const gitignorePath = resolve(directory, '.gitignore');

export default tseslint.config(
includeIgnoreFile(gitignorePath),
...cloudflightTypescriptFormatConfig,
);
```

With the command `eslint . --config .eslintrc.format.js` your project can be checked for formatting violations.
With the command `eslint -c eslint.format.mjs .` your project can be checked for formatting violations.

### Pre-Commit Hook

Expand All @@ -102,7 +104,7 @@ To automatically format your code before committing, set up [husky](https://typi
{
// ...
"lint-staged": {
"*.ts": "eslint --config .eslintrc.format.cjs --fix"
"*.ts": "eslint -c eslint.format.mjs --fix"
}
}
```
1 change: 1 addition & 0 deletions packages/eslint-plugin-typescript/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {Config} from 'jest';

import {baseJestConfig} from '../../jest.config.base';

const jestConfig: Config = {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-typescript",
"version": "1.0.0-rc9",
"version": "1.0.0-rc10",
"description": "Cloudflight eslint-plugin & eslint-config for typescript",
"volta": {
"extends": "../../package.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-typescript/src/configs/custom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TSESLint} from '@typescript-eslint/utils';
import type {TSESLint} from '@typescript-eslint/utils';

import {NoMomentJsRuleName} from '../rules/typescript/no-moment-js';
import {NoOnEventAssignName} from '../rules/typescript/no-on-event-assign';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-typescript/src/configs/eslint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {TSESLint} from '@typescript-eslint/utils';
import type {TSESLint} from '@typescript-eslint/utils';

export const eslintRules: TSESLint.Linter.RulesRecord = {
complexity: ['error', {max: 20}],
Expand Down
Loading
Loading