Skip to content

Commit 0ed362e

Browse files
authored
Merge pull request #2 from heap-code/develop
Add configuration presets
2 parents a795f19 + d7375d9 commit 0ed362e

File tree

8 files changed

+72
-3
lines changed

8 files changed

+72
-3
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
}
209209
},
210210
{
211-
"files": ["jest.config.ts", "src/index.ts"],
211+
"files": ["jest.config.ts", "src/index.ts", "src/configs/*.ts"],
212212
"rules": {
213213
"import/no-default-export": "off"
214214
}

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,24 @@ The different rules can be defined as follows:
5454
}
5555
```
5656

57-
> All these configuration can be done on a `override` section:
57+
Or simply extends a configuration preset:
58+
59+
```json
60+
{
61+
"extends": ["plugin:sort-decorators/recommended"]
62+
}
63+
```
64+
65+
### Configuration presets
66+
67+
| Name | Description |
68+
|:-------------------------------------|:---------------------------------------------------------------|
69+
| `plugin:sort-decorators/recommended` | Enables all rules with a `warn` security level. |
70+
| `plugin:sort-decorators/strict` | Enables all rules with a `error` security level and `autoFix`. |
71+
72+
---
73+
74+
> All this configuration can be done on a `override` section:
5875
> <https://eslint.org/docs/latest/use/configure/configuration-files#how-do-overrides-work>
5976
6077
## Rules
@@ -72,3 +89,7 @@ The different rules can be defined as follows:
7289
| [sort-on-properties](docs/rules/sort-on-properties.md) | Enforces order of properties decorators | 🔧 |
7390

7491
<!-- end auto-generated rules list -->
92+
93+
## Releases
94+
95+
See information about breaking changes and release notes [here](https://github.com/heap-code/eslint-plugin-sort-decorators/blob/HEAD/CHANGELOG.md).

jest.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as path from "path";
22
import { JestConfigWithTsJest } from "ts-jest";
33

44
export default {
5-
collectCoverageFrom: ["<rootDir>/src/**/*.ts", "!<rootDir>/src/**/index.ts"],
5+
collectCoverageFrom: [
6+
"<rootDir>/src/**/*.ts",
7+
"!<rootDir>/src/**/index.ts",
8+
"!<rootDir>/src/configs/*.ts"
9+
],
610
coverageThreshold: { global: { branches: 75, functions: 75, lines: 75, statements: 75 } },
711
moduleFileExtensions: ["js", "ts"],
812
setupFilesAfterEnv: [path.resolve(__dirname, "./tools/jest/jest-extended.ts")],

src/configs/common.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { TSESLint } from "@typescript-eslint/utils";
2+
import { Linter } from "eslint";
3+
4+
import { SortRuleOptions } from "../lib/sort-rule";
5+
import {
6+
SORT_ON_ACCESSORS_NAME,
7+
SORT_ON_CLASSES_NAME,
8+
SORT_ON_METHODS_NAME,
9+
SORT_ON_PARAMETERS_NAME,
10+
SORT_ON_PROPERTIES_NAME
11+
} from "../rules";
12+
13+
export const PLUGIN_NAME = "sort-decorators";
14+
15+
/**
16+
* @param ruleEntry the rule entry to set to all rules
17+
* @returns A configuration with all its rules set with the given entry
18+
*/
19+
export function createConfiguration(ruleEntry: Linter.RuleEntry<[SortRuleOptions]>) {
20+
return {
21+
parser: "@typescript-eslint/parser",
22+
plugins: [PLUGIN_NAME],
23+
rules: {
24+
[`${PLUGIN_NAME}/${SORT_ON_ACCESSORS_NAME}`]: ruleEntry,
25+
[`${PLUGIN_NAME}/${SORT_ON_CLASSES_NAME}`]: ruleEntry,
26+
[`${PLUGIN_NAME}/${SORT_ON_METHODS_NAME}`]: ruleEntry,
27+
[`${PLUGIN_NAME}/${SORT_ON_PARAMETERS_NAME}`]: ruleEntry,
28+
[`${PLUGIN_NAME}/${SORT_ON_PROPERTIES_NAME}`]: ruleEntry
29+
}
30+
} as const satisfies TSESLint.Linter.Config;
31+
}

src/configs/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { recommended } from "./recommended";
2+
export { strict } from "./strict";

src/configs/recommended.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createConfiguration } from "./common";
2+
3+
export const recommended = createConfiguration("warn");

src/configs/strict.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createConfiguration } from "./common";
2+
3+
export const strict = createConfiguration(["error", { autoFix: true }]);

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TSESLint } from "@typescript-eslint/utils";
22

3+
import * as configs from "./configs";
34
import {
45
SORT_ON_ACCESSORS_NAME,
56
SORT_ON_CLASSES_NAME,
@@ -14,6 +15,10 @@ import {
1415
} from "./rules";
1516

1617
export default {
18+
configs: {
19+
recommended: configs.recommended,
20+
strict: configs.strict
21+
},
1722
rules: {
1823
[SORT_ON_ACCESSORS_NAME]: sortOnAccessors,
1924
[SORT_ON_CLASSES_NAME]: sortOnClasses,

0 commit comments

Comments
 (0)