Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@angular/compiler": "catalog:",
"@commitlint/cli": "catalog:",
"@commitlint/config-conventional": "catalog:",
"@eslint/core": "catalog:",
"@mdn/browser-compat-data": "catalog:",
"@nx/devkit": "catalog:",
"@nx/esbuild": "catalog:",
Expand Down
25 changes: 16 additions & 9 deletions packages/angular-eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tsPluginBase from '@angular-eslint/eslint-plugin';
import templatePluginBase from '@angular-eslint/eslint-plugin-template';
import * as templateParserBase from '@angular-eslint/template-parser';
import type { Plugin as ESLintPlugin } from '@eslint/core';
import type { TSESLint } from '@typescript-eslint/utils';
import { parser } from 'typescript-eslint';

Expand All @@ -16,7 +17,9 @@ const templateParser: TSESLint.FlatConfig.Parser = {
};

/*
we could build a plugin object here without the `configs` key - but if we do
NOTE: Comment and approach taken from typescript-eslint:

We could build a plugin object here without the `configs` key - but if we do
that then we create a situation in which
```
require('angular-eslint').tsPlugin !== require('@angular-eslint/eslint-plugin')
Expand All @@ -38,14 +41,18 @@ use our new package); however legacy configs consumed via `@eslint/eslintrc`
would never be able to satisfy this constraint and thus users would be blocked
from using them.
*/
const tsPlugin: TSESLint.FlatConfig.Plugin = tsPluginBase as Omit<
typeof tsPluginBase,
'configs'
>;
const templatePlugin: TSESLint.FlatConfig.Plugin = templatePluginBase as Omit<
typeof templatePluginBase,
'configs'
>;

/**
* Make the plugins compatible with both ESLint's Plugin type and typescript-eslint's
* FlatConfig.Plugin type through type assertion.
*
* This is covered by a type compatibility test in tests/type-compatibility.test.ts
*/
type CompatiblePlugin = Omit<ESLintPlugin, 'configs'> & {
configs?: never;
};
const tsPlugin = tsPluginBase as unknown as CompatiblePlugin;
const templatePlugin = templatePluginBase as unknown as CompatiblePlugin;

const configs = {
tsAll: tsAllConfig(tsPlugin, parser),
Expand Down
64 changes: 64 additions & 0 deletions packages/angular-eslint/tests/type-compatibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* This test file exists purely to be type-checked in CI to ensure that angular-eslint plugins and parsers are compatible with both:
* 1. ESLint's defineConfig function (uses ESLint.Plugin and Linter.ParserModule types)
* 2. typescript-eslint's config function (uses TSESLint.FlatConfig.Plugin and TSESLint.FlatConfig.Parser types)
*/

import { defineConfig } from 'eslint/config';
import { config } from 'typescript-eslint';

import angular from '../src/index';

/**
* Test 1: Verify compatibility with ESLint's defineConfig
*/
defineConfig([
{
files: ['**/*.ts'],
plugins: {
'@angular-eslint': angular.tsPlugin,
},
rules: {
'@angular-eslint/component-class-suffix': 'error',
},
},
{
files: ['**/*.html'],
plugins: {
'@angular-eslint/template': angular.templatePlugin,
},
languageOptions: {
parser: angular.templateParser,
},
rules: {
'@angular-eslint/template/banana-in-box': 'error',
},
},
]);

/**
* Test 2: Verify compatibility with typescript-eslint's config function
*/
config(
{
files: ['**/*.ts'],
plugins: {
'@angular-eslint': angular.tsPlugin,
},
rules: {
'@angular-eslint/component-class-suffix': 'error',
},
},
{
files: ['**/*.html'],
plugins: {
'@angular-eslint/template': angular.templatePlugin,
},
languageOptions: {
parser: angular.templateParser,
},
rules: {
'@angular-eslint/template/banana-in-box': 'error',
},
},
);
3 changes: 3 additions & 0 deletions packages/angular-eslint/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
},
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.type-compat.json"
}
]
}
15 changes: 15 additions & 0 deletions packages/angular-eslint/tsconfig.type-compat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc/angular-eslint-type-compat",
"types": ["node"],
"sourceMap": true,
"skipLibCheck": false
},
"include": ["tests/type-compatibility.test.ts"],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ catalog:
'@angular/compiler': 20.3.9
'@commitlint/cli': 20.1.0
'@commitlint/config-conventional': 20.0.0
'@eslint/core': ^0.17.0
'@mdn/browser-compat-data': 7.1.18
'@nx/devkit': 22.1.0-beta.3
'@nx/esbuild': 22.1.0-beta.3
Expand Down