Skip to content

Commit

Permalink
simplify plugin setup (#251)
Browse files Browse the repository at this point in the history
* - simplify plugin setup

Signed-off-by: Jakob Fischl <[email protected]>

* - fix react configuration discarding import-x settings

Signed-off-by: Jakob Fischl <[email protected]>

* bump version

Signed-off-by: Jakob Fischl <[email protected]>

---------

Signed-off-by: Jakob Fischl <[email protected]>
Signed-off-by: Jakob Fischl <[email protected]>
  • Loading branch information
jakob0fischl authored Nov 5, 2024
1 parent bc9f222 commit 6b59697
Show file tree
Hide file tree
Showing 19 changed files with 320 additions and 339 deletions.
54 changes: 54 additions & 0 deletions CUSTOM_CONFIGURATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

# Custom Configuration
These configs are intended to be used as is without any customization, but we do recognize that some projects may have special requirements.

## Custom tsconfig files
By default, only tsconfig files in the root directory are used. You can provide custom tsconfig files like this:

```ts
// this applies to all configs, not just typescript
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';

export default cloudflightTypescriptConfig({
rootDirectory: import.meta.dirname,
tsConfigFiles: ['./packages/*/tsconfig.json', './packages/*/tsconfig.spec.json'],
});
```
**Try to keep the list of TSConfig files as short as possible, they have a negative effect on performance**

## Adding additional plugins
Add additional things before the Cloudflight config, this prevents these plugins from overriding important config options.

**Note:** This might not work for all Plugins

```ts
// this applies to all configs, not just typescript
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';

export default [
...storybook.configs['flat/recommended'],
...cloudflightTypescriptConfig({
rootDirectory: import.meta.dirname,
tsConfigFiles: ['./packages/*/tsconfig.json', './packages/*/tsconfig.spec.json'],
})
];
```

## Disabling rules

```ts
// this applies to all configs, not just typescript
import { cloudflightTypescriptConfig } from '@cloudflight/eslint-plugin-typescript';

export default [
...cloudflightTypescriptConfig({
rootDirectory: import.meta.dirname,
tsConfigFiles: ['./packages/*/tsconfig.json', './packages/*/tsconfig.spec.json'],
}),
{
rules: {
'no-magic-numbers': 'off',
},
},
];
```
22 changes: 4 additions & 18 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {cloudflightTypescriptConfig} 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),
...cloudflightTypescriptConfig({
rootDirectory: import.meta.dirname,
tsConfigFiles: ['./packages/*/tsconfig.json', './packages/*/tsconfig.spec.json'],
}),
{
// these files are temporarily disabled for linting
// until we are done with migrating everything to v9
Expand All @@ -18,7 +14,6 @@ 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/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',
Expand All @@ -28,15 +23,6 @@ export default tseslint.config(
'jest.config*.ts',
],
},
...cloudflightTypescriptConfig,
{
languageOptions: {
parserOptions: {
project: ['./packages/*/tsconfig.json', './packages/*/tsconfig.spec.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
{
rules: {
'import-x/no-named-as-default-member': 'off',
Expand Down
15 changes: 3 additions & 12 deletions eslint.format.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
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,
);
export default cloudflightTypescriptFormatConfig({
rootDirectory: import.meta.dirname,
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin",
"version": "1.0.0-rc12",
"version": "1.0.0-rc13",
"private": true,
"volta": {
"node": "20.18.0",
Expand Down
40 changes: 9 additions & 31 deletions packages/eslint-plugin-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ The following dependencies are required:

In your `package.json` add the following:

```
```json
"devDependencies": {
...
"@cloudflight/eslint-plugin-angular": "<version>",
...
}
}
```

The plugin provides 3 different configurations:
Expand All @@ -37,47 +37,25 @@ Now open your `eslint.config.mjs` and add one of the configurations:

```ts
import { cloudflightAngularConfig } from '@cloudflight/eslint-plugin-angular';
import { includeIgnoreFile } from '@eslint/compat';
import { dirname, normalize, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

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

export default [
includeIgnoreFile(gitignorePath),
...cloudflightAngularConfig,
{
languageOptions: {
parserOptions: {
project: ['tsconfig*(.*).json'],
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['tsconfig*(.*).json'],
},
},
},
},
];

export default cloudflightAngularConfig({
rootDirectory: import.meta.dirname,
});
```
See [Custom Configuration](../../CUSTOM_CONFIGURATION.md) for more complicated project setups.

## Formatting

This package also includes configs for formatting typescript.

In your `package.json` add the following:

```
```json
"devDependencies": {
...
"@cloudflight/eslint-plugin-angular": "<version>",
...
}
}
```

Create a new file called `.eslintrc.format.js` and add the following:
Expand Down
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-rc12",
"version": "1.0.0-rc13",
"description": "Cloudflight eslint-plugin & eslint-config for angular",
"volta": {
"extends": "../../package.json"
Expand Down
20 changes: 12 additions & 8 deletions packages/eslint-plugin-angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {cloudflightTypescriptConfig} from '@cloudflight/eslint-plugin-typescript';
import type {FlatConfig} from '@typescript-eslint/utils/ts-eslint';

import {CloudflightEslintPluginSettings, cloudflightTypescriptConfig} from '@cloudflight/eslint-plugin-typescript';
import angular from 'angular-eslint';
import tseslint from 'typescript-eslint';

Expand All @@ -7,8 +9,7 @@ import {angularTemplateEslintRules} from './configs/angular-eslint-template';
import {eslintRules} from './configs/eslint';
import {typescriptEslintRules} from './configs/typescript-eslint';

export const cloudflightAngularTypescriptConfig = tseslint.config(
...cloudflightTypescriptConfig,
const cloudflightAngularTypescriptConfig = tseslint.config(
{
files: ['**/*.{ts,mts,cts}'],
extends: [
Expand All @@ -24,7 +25,7 @@ export const cloudflightAngularTypescriptConfig = tseslint.config(
},
);

export const cloudflightAngularTemplateConfig = tseslint.config(
const cloudflightAngularTemplateConfig = tseslint.config(
{
files: ['**/*.html'],
extends: [
Expand All @@ -40,7 +41,10 @@ export const cloudflightAngularTemplateConfig = tseslint.config(
},
);

export const cloudflightAngularConfig = tseslint.config(
...cloudflightAngularTypescriptConfig,
...cloudflightAngularTemplateConfig,
);
export function cloudflightAngularConfig(settings: CloudflightEslintPluginSettings): FlatConfig.ConfigArray {
return tseslint.config(
...cloudflightTypescriptConfig(settings),
...cloudflightAngularTypescriptConfig,
...cloudflightAngularTemplateConfig,
);
}
36 changes: 7 additions & 29 deletions packages/eslint-plugin-node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,21 @@ The following dependencies are required:

In your `package.json` add the following:

```
```json
"devDependencies": {
...
"@cloudflight/eslint-plugin-node": "<version>",
...
}
}
```

Now open your `eslint.config.mjs` and add one of the configurations:

```ts
import { cloudflightNodeConfig } from '@cloudflight/eslint-plugin-node';
import { includeIgnoreFile } from '@eslint/compat';
import { dirname, normalize, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

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

export default [
includeIgnoreFile(gitignorePath),
...cloudflightNodeConfig,
{
languageOptions: {
parserOptions: {
project: ['tsconfig*(.*).json'],
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
'import-x/resolver': {
typescript: {
alwaysTryTypes: true,
project: ['tsconfig*(.*).json'],
},
},
},
},
];

export default cloudflightNodeConfig({
rootDirectory: import.meta.dirname,
});
```
See [Custom Configuration](../../CUSTOM_CONFIGURATION.md) for more complicated project setups.
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-rc12",
"version": "1.0.0-rc13",
"description": "Cloudflight eslint-plugin & eslint-config for node",
"volta": {
"extends": "../../package.json"
Expand Down
38 changes: 21 additions & 17 deletions packages/eslint-plugin-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {cloudflightTypescriptConfig} from '@cloudflight/eslint-plugin-typescript';
import type {FlatConfig} from '@typescript-eslint/utils/ts-eslint';

import {CloudflightEslintPluginSettings, 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';
Expand All @@ -8,20 +10,22 @@ import {importEslintRules} from './configs/import';
import {nodeRules} from './configs/node';
import {securityRules} from './configs/security';

export const cloudflightNodeConfig = tseslint.config(
...cloudflightTypescriptConfig,
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
extends: [
pluginNode.configs['flat/recommended'],
nounsanitized.configs.recommended,
pluginSecurity.configs.recommended,
],
name: 'cloudflight/node/rules',
rules: {
...nodeRules,
...securityRules,
...importEslintRules,
export function cloudflightNodeConfig(settings: CloudflightEslintPluginSettings): FlatConfig.ConfigArray {
return tseslint.config(
...cloudflightTypescriptConfig(settings),
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
extends: [
pluginNode.configs['flat/recommended'],
nounsanitized.configs.recommended,
pluginSecurity.configs.recommended,
],
name: 'cloudflight/node/rules',
rules: {
...nodeRules,
...securityRules,
...importEslintRules,
},
},
},
);
);
}
Loading

0 comments on commit 6b59697

Please sign in to comment.