Skip to content

Commit

Permalink
fix angular doc and exports
Browse files Browse the repository at this point in the history
Signed-off-by: Kangrui Johann Ye <kangrui.ye@cloudflight.io>
  • Loading branch information
strawberry-choco committed Dec 18, 2024
1 parent 0959d49 commit 0cad831
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 74 deletions.
49 changes: 0 additions & 49 deletions packages/eslint-plugin-angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": "<version>",
...
}
```

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"
}
}
```
8 changes: 0 additions & 8 deletions packages/eslint-plugin-angular/src/configs/format-template.ts

This file was deleted.

36 changes: 19 additions & 17 deletions packages/eslint-plugin-angular/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -43,8 +46,7 @@ const cloudflightAngularTemplateConfig = tseslint.config(

export function cloudflightAngularConfig(settings: CloudflightEslintPluginSettings): FlatConfig.ConfigArray {
return tseslint.config(
...cloudflightTypescriptConfig(settings),
...cloudflightAngularTypescriptConfig,
...cloudflightAngularTypescriptConfig(settings),
...cloudflightAngularTemplateConfig,
);
}

0 comments on commit 0cad831

Please sign in to comment.