Skip to content

Commit 6aa5cc3

Browse files
author
Mendes Hugo
committed
feat(preset): add configuration presets
1 parent a795f19 commit 6aa5cc3

File tree

7 files changed

+50
-2
lines changed

7 files changed

+50
-2
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
}

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)