Skip to content

Commit db3f937

Browse files
test: add example for testing react eslint
1 parent 7f6160f commit db3f937

File tree

15 files changed

+175
-207
lines changed

15 files changed

+175
-207
lines changed

eslint.config.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import tsConfig from "typescript-eslint";
21
import prettierConfig from "eslint-config-prettier";
3-
import harmonixConfig from "@harmonix-hub/eslint";
2+
import hxh from "@harmonix-hub/eslint";
43

54
/** @type import("eslint").Linter.Config */
65
export default [
76
{
87
files: ["*.ts", "*.tsx"]
98
},
109
{
11-
ignores: ["dist", "node_modules", "**/*.js"]
10+
ignores: ["dist", "node_modules", "/**/*.d.ts", "**/*.js"]
1211
},
13-
...tsConfig.configs.recommended,
14-
harmonixConfig.tsConfigs,
15-
harmonixConfig.reactConfigs,
16-
harmonixConfig.jestConfigs,
12+
...hxh.tsConfigs,
13+
hxh.reactConfigs,
1714
prettierConfig,
1815
];
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { jestConfig } from "@harmonix-hub/testing";
22

33
module.exports = {
4-
...jestConfig()
4+
...jestConfig,
5+
testEnvironment: "jsdom",
56
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"prepare": "husky install",
77
"build": "turbo run build",
88
"lint": "turbo run lint --parallel",
9-
"lint:test": "eslint .",
109
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1110
"test": "turbo run test --parallel",
1211
"clean": "turbo clean && rm -rf node_modules",
12+
"example:lint": "eslint .",
13+
"example:test": "jest",
1314
"changelog:conventional": "changeset-conventional",
1415
"changelog:package": "changeset",
1516
"changelog:generate": "npm run changelog:conventional & npm run packages:version",
@@ -33,8 +34,7 @@
3334
"jest": "^29.7.0",
3435
"react": "^19.0.0",
3536
"turbo": "^2.3.3",
36-
"typescript": "^5.7.2",
37-
"typescript-eslint": "^8.17.0"
37+
"typescript": "^5.7.2"
3838
},
3939
"optionalDependencies": {
4040
"@nx/nx-linux-x64-gnu": "^20.2.2"

packages/eslint/README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This package provides ESLint configurations for projects developed with Harmonix
77
You can install this ESLint configuration package using npm.
88

99
```bash
10-
npm install @typescript-eslint eslint-config-prettier @harmonix-hub/eslint --save-dev
10+
npm install eslint-config-prettier @harmonix-hub/eslint --save-dev
1111
```
1212

1313
## Usage
@@ -17,24 +17,23 @@ To use the ESLint configurations provided by this package, create an ESLint conf
1717
Example `eslint.config.mjs` configuration file:
1818

1919
```js
20-
import tsConfig from "typescript-eslint";
2120
import prettierConfig from "eslint-config-prettier";
22-
import harmonixConfig from "@harmonix-hub/eslint";
21+
import hxh from "@harmonix-hub/eslint";
2322

2423
/** @type import("eslint").Linter.Config */
2524
export default [
2625
{
27-
ignores: ["dist", "node_modules", "**/*.js"]
26+
files: ["*.ts", "*.tsx"]
2827
},
2928
{
30-
files: ["**/*.ts", "**/*.tsx"]
29+
ignores: ["dist", "node_modules", "**/*.js"]
3130
},
32-
...tsConfig.configs.recommended,
33-
harmonixConfig.tsConfigs,
34-
harmonixConfig.reactConfigs,
35-
harmonixConfig.jestConfigs,
31+
...hxh.tsConfigs,
32+
hxh.reactConfigs,
33+
hxh.jestConfigs,
3634
prettierConfig,
3735
];
36+
3837
```
3938

4039
By extending `@harmonix-hub/eslint`, you inherit the recommended ESLint rules for Harmonix hub projects.

packages/eslint/__tests__/index.test.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/eslint/custom.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
/**
2+
* Declaration module for the "eslint-plugin-react-hooks" package.
3+
* This module defines the types for the plugin, including its rules and configurations.
4+
*/
15
declare module "eslint-plugin-react-hooks" {
26
import type { ESLint, Rule } from "eslint";
7+
8+
/** Represents the React Hooks ESLint plugin. */
39
const plugin: Omit<ESLint.Plugin, "configs"> & {
10+
/** Plugin configuration options. */
411
configs: {
12+
/** Partial rules configuration for the recommended settings. */
513
recommended: Partial<Rules>;
614
};
15+
/** Collection of ESLint rules provided by the plugin. */
716
rules: Rule;
817
};
18+
919
export default plugin;
1020
}

packages/eslint/package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@
1010
"scripts": {
1111
"build": "tsc -p tsconfig.json",
1212
"lint": "eslint .",
13-
"clean": "rm -rf dist node_modules",
14-
"test": "jest"
13+
"clean": "rm -rf dist node_modules"
1514
},
1615
"peerDependencies": {
1716
"eslint": "^9.16.0"
1817
},
1918
"dependencies": {
20-
"typescript-eslint": "^8.17.0",
21-
"@babel/eslint-parser": "^7.25.9",
19+
"typescript-eslint": "^8.18.0",
2220
"@typescript-eslint/eslint-plugin": "^8.18.0",
23-
"eslint-config-prettier": "^9.1.0",
2421
"eslint-plugin-tsdoc": "^0.4.0",
25-
"eslint-plugin-jest": "^28.9.0",
2622
"eslint-plugin-jsdoc": "^50.6.1",
23+
"eslint-plugin-jest": "^28.9.0",
2724
"eslint-plugin-jsx-a11y": "^6.10.2",
2825
"eslint-plugin-react": "^7.37.2",
2926
"eslint-plugin-react-hooks": "^5.1.0",

packages/eslint/src/jest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const jestConfigs: Linter.Config = {
2525
languageOptions,
2626
rules: {
2727
"jest/no-mocks-import": "off",
28-
// Added this so test file don't give error when accessing DOM element using DOM api
28+
// Added this so test file don't give error when accessing DOM element using DOM API
2929
"testing-library/no-node-access": "off"
3030
}
3131
};

packages/eslint/src/typescript.ts

Lines changed: 99 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import jsDocConfig from "eslint-plugin-jsdoc";
2+
import tsConfig, { type Config } from "typescript-eslint";
23
import tsDocConfig from "eslint-plugin-tsdoc";
34
import globals from "globals";
45
import unusedImports from "eslint-plugin-unused-imports";
@@ -16,83 +17,104 @@ const languageOptions: Linter.Config["languageOptions"] = {
1617
...globals.es2021
1718
}
1819
};
19-
export const tsConfigs: Linter.Config = {
20-
plugins: {
21-
jsdoc: jsDocConfig,
22-
tsdoc: tsDocConfig,
23-
"unused-imports": unusedImports
20+
export const tsConfigs: Config = [
21+
...tsConfig.configs.recommended,
22+
{
23+
ignores: ["dist", "node_modules"]
2424
},
25-
languageOptions,
26-
rules: {
27-
"array-bracket-newline": ["error", "consistent"],
28-
"array-bracket-spacing": ["error", "never"],
29-
"array-callback-return": "error",
30-
"array-element-newline": [
31-
"error",
32-
{
33-
ArrayExpression: "consistent",
34-
ArrayPattern: { minItems: 3 }
35-
}
36-
],
37-
"arrow-spacing": "error",
38-
"brace-style": ["error", "1tbs"],
39-
"comma-dangle": ["error", "never"],
40-
"comma-spacing": [
41-
"error",
42-
{
43-
after: true,
44-
before: false
45-
}
46-
],
47-
curly: ["error", "all"],
48-
"default-case": "off",
49-
eqeqeq: ["error", "always"],
50-
"func-call-spacing": ["error", "never"],
51-
"function-call-argument-newline": ["error", "consistent"],
52-
indent: ["error", 4, { SwitchCase: 1, ignoredNodes: ["ConditionalExpression"] }],
53-
"jsdoc/newline-after-description": 0, // Required for vs code auto formatting
54-
"jsdoc/require-hyphen-before-param-description": 1,
55-
"jsdoc/require-jsdoc": [
56-
"error",
57-
{
58-
require: {
59-
ArrowFunctionExpression: true,
60-
ClassExpression: true,
61-
FunctionDeclaration: true,
62-
FunctionExpression: true,
63-
MethodDefinition: true
25+
{
26+
files: ["*.ts", "*.tsx"],
27+
plugins: {
28+
tsdoc: tsDocConfig
29+
},
30+
rules: {
31+
"tsdoc/syntax": "warn"
32+
}
33+
},
34+
{
35+
plugins: {
36+
jsdoc: jsDocConfig,
37+
"unused-imports": unusedImports
38+
},
39+
languageOptions,
40+
rules: {
41+
"array-bracket-newline": ["error", "consistent"],
42+
"array-bracket-spacing": ["error", "never"],
43+
"array-callback-return": "error",
44+
"array-element-newline": [
45+
"error",
46+
{
47+
ArrayExpression: "consistent",
48+
ArrayPattern: { minItems: 3 }
49+
}
50+
],
51+
"arrow-spacing": "error",
52+
"brace-style": ["error", "1tbs"],
53+
"comma-dangle": ["error", "never"],
54+
"comma-spacing": [
55+
"error",
56+
{
57+
after: true,
58+
before: false
59+
}
60+
],
61+
curly: ["error", "all"],
62+
"default-case": "off",
63+
eqeqeq: ["error", "always"],
64+
"func-call-spacing": ["error", "never"],
65+
"function-call-argument-newline": ["error", "consistent"],
66+
indent: ["error", 4, { SwitchCase: 1, ignoredNodes: ["ConditionalExpression"] }],
67+
"jsdoc/newline-after-description": 0,
68+
"jsdoc/require-hyphen-before-param-description": 1,
69+
"jsdoc/require-jsdoc": [
70+
"error",
71+
{
72+
require: {
73+
ArrowFunctionExpression: true,
74+
ClassDeclaration: true,
75+
ClassExpression: true,
76+
FunctionDeclaration: true,
77+
FunctionExpression: true,
78+
MethodDefinition: true
79+
},
80+
contexts: [
81+
"TSInterfaceDeclaration",
82+
"TSTypeAliasDeclaration",
83+
"TSEnumDeclaration",
84+
"TSPropertySignature"
85+
]
6486
}
65-
}
66-
],
67-
"keyword-spacing": ["error", { after: true, before: true }],
68-
"no-console": "error",
69-
"no-dupe-else-if": "error",
70-
"no-extend-native": "off",
71-
"no-nested-ternary": "error",
72-
"object-curly-newline": ["error", { consistent: true, multiline: true }],
73-
"object-curly-spacing": ["error", "always"],
74-
"object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
75-
"padding-line-between-statements": [
76-
"error",
77-
// Always one empty line before return statement
78-
{
79-
blankLine: "always",
80-
next: "return",
81-
prev: "*"
82-
},
83-
// Always one empty line between methods
84-
{
85-
blankLine: "always",
86-
next: ["block-like", "multiline-block-like"],
87-
prev: ["block-like", "multiline-block-like"]
88-
},
89-
// Avoids more than one empty line
90-
{
91-
blankLine: "never",
92-
next: "empty",
93-
prev: "empty"
94-
}
95-
],
96-
"space-before-blocks": "error"
87+
],
88+
"keyword-spacing": ["error", { after: true, before: true }],
89+
"no-console": "error",
90+
"no-dupe-else-if": "error",
91+
"no-extend-native": "off",
92+
"no-nested-ternary": "error",
93+
"object-curly-newline": ["error", { consistent: true, multiline: true }],
94+
"object-curly-spacing": ["error", "always"],
95+
"object-property-newline": ["error", { allowAllPropertiesOnSameLine: true }],
96+
"padding-line-between-statements": [
97+
"error",
98+
// Always one empty line before return statement
99+
{
100+
blankLine: "always",
101+
next: "return",
102+
prev: "*"
103+
},
104+
// Always one empty line between methods
105+
{
106+
blankLine: "always",
107+
next: ["block-like", "multiline-block-like"],
108+
prev: ["block-like", "multiline-block-like"]
109+
},
110+
// Avoids more than one empty line
111+
{
112+
blankLine: "never",
113+
next: "empty",
114+
prev: "empty"
115+
}
116+
],
117+
"space-before-blocks": "error"
118+
}
97119
}
98-
};
120+
];

packages/stylelint/__tests__/index.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { getStyleLintConfig } from "../src/index";
2-
3-
describe("getStyleLintConfig", () => {
4-
it("returns a valid Stylelint configuration object", () => {
5-
const stylelintConfig = getStyleLintConfig();
1+
import { stylelintConfig } from "../src/index";
62

3+
describe("stylelintConfig", () => {
4+
it("returns a valid style lint configuration object", () => {
75
// Basic structure checks
86
expect(stylelintConfig).toHaveProperty("customSyntax");
97
expect(stylelintConfig).toHaveProperty("extends");

0 commit comments

Comments
 (0)