diff --git a/packages/eslint-plugin-angular/README.md b/packages/eslint-plugin-angular/README.md index 2f5f0d2..9945ff2 100644 --- a/packages/eslint-plugin-angular/README.md +++ b/packages/eslint-plugin-angular/README.md @@ -52,52 +52,3 @@ export default [ ]; ``` 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": "", - ... -} -``` - -Create a new file called `.eslintrc.format.js` and add the following: - -``` -require('@rushstack/eslint-patch/modern-module-resolution'); - -module.exports = { - root: true, - plugins: ['@cloudflight/typescript'], - extends: ['plugin:@cloudflight/angular/formatting'], - ignorePatterns: ['jest.config*.ts'], - env: { - es6: true, - node: true, - }, -}; -``` - -With the command `eslint . --config .eslintrc.format.js` your project can be checked for formatting violations. - -### Pre-Commit Hook - -The reason we created another eslint config file just for formatting instead of adding it to the existing one is to separate between linting and formatting, which are two different concerns. Furthermore, with the separation we also gain the ability to fix the formatting automatically before commit. Automatically fixing linting bugs with `eslint --fix` is not recommended, since it changes the intent of the code. - -To automatically format your code before committing, set up [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) with the following content in your `package.json`. - -```json -{ - // ... - "lint-staged": { - "*.html": "eslint --config .eslintrc.format.cjs --fix", - "*.ts": "eslint --config .eslintrc.format.cjs --fix" - } -} -``` diff --git a/packages/eslint-plugin-angular/src/configs/format-template.ts b/packages/eslint-plugin-angular/src/configs/format-template.ts deleted file mode 100644 index ec63c1c..0000000 --- a/packages/eslint-plugin-angular/src/configs/format-template.ts +++ /dev/null @@ -1,8 +0,0 @@ -import {TSESLint} from '@typescript-eslint/utils'; - -const pluginPrefix = '@angular-eslint/template'; - -export const formatAngularTemplateEslintRules: TSESLint.Linter.RulesRecord = { - [`${pluginPrefix}/attributes-order`]: 'error', - [`${pluginPrefix}/no-interpolation-in-attributes`]: 'error', -}; diff --git a/packages/eslint-plugin-angular/src/index.ts b/packages/eslint-plugin-angular/src/index.ts index ef3ba7a..1e7801d 100644 --- a/packages/eslint-plugin-angular/src/index.ts +++ b/packages/eslint-plugin-angular/src/index.ts @@ -9,23 +9,26 @@ import {angularTemplateEslintRules} from './configs/angular-eslint-template'; import {eslintRules} from './configs/eslint'; import {typescriptEslintRules} from './configs/typescript-eslint'; -const cloudflightAngularTypescriptConfig = tseslint.config( - { - files: ['**/*.{ts,mts,cts}'], - extends: [ - ...angular.configs.tsRecommended, - ], - processor: angular.processInlineTemplates, - name: 'cloudflight/angular/typescript/rules', - rules: { - ...eslintRules, - ...typescriptEslintRules, - ...angularEslintRules, +export function cloudflightAngularTypescriptConfig(settings: CloudflightEslintPluginSettings): FlatConfig.ConfigArray { + return tseslint.config( + ...cloudflightTypescriptConfig(settings), + { + files: ['**/*.{ts,mts,cts}'], + extends: [ + ...angular.configs.tsRecommended, + ], + processor: angular.processInlineTemplates, + name: 'cloudflight/angular/typescript/rules', + rules: { + ...eslintRules, + ...typescriptEslintRules, + ...angularEslintRules, + }, }, - }, -); + ); +} -const cloudflightAngularTemplateConfig = tseslint.config( +export const cloudflightAngularTemplateConfig = tseslint.config( { files: ['**/*.html'], extends: [ @@ -43,8 +46,7 @@ const cloudflightAngularTemplateConfig = tseslint.config( export function cloudflightAngularConfig(settings: CloudflightEslintPluginSettings): FlatConfig.ConfigArray { return tseslint.config( - ...cloudflightTypescriptConfig(settings), - ...cloudflightAngularTypescriptConfig, + ...cloudflightAngularTypescriptConfig(settings), ...cloudflightAngularTemplateConfig, ); }