Skip to content

Commit 4ad1787

Browse files
committed
chore: Run ESLint
1 parent b93461e commit 4ad1787

6 files changed

Lines changed: 1848 additions & 31 deletions

File tree

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,32 @@ jobs:
3232
- run: pip install pre-commit
3333
- run: SKIP=fmt,cargo-check,clippy pre-commit run --all-files
3434

35+
eslint:
36+
name: ESLint
37+
runs-on: ubuntu-22.04
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Setup node
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: 20
45+
46+
- name: Cache NPM dependencies
47+
uses: actions/cache@v3
48+
with:
49+
path: node_modules
50+
key: npm-cache-lint-node@16-${{ hashFiles('yarn.lock') }}
51+
working-directory: ./bindings/javascript
52+
53+
- name: "Install dependencies"
54+
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
55+
working-directory: ./bindings/javascript
56+
57+
- name: ESLint
58+
run: yarn lint
59+
working-directory: ./bindings/javascript
60+
3561
test-stable:
3662
name: Test (stable)
3763
runs-on: ubuntu-22.04

bindings/javascript/.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
js-binding.js
2+
js-binding.d.ts
3+
target
4+
wasm
5+
wasm/dist

bindings/javascript/.eslintrc.yml

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
parser: "@typescript-eslint/parser"
2+
3+
parserOptions:
4+
ecmaFeatures:
5+
jsx: true
6+
ecmaVersion: latest
7+
sourceType: module
8+
9+
globals:
10+
Deno: readonly
11+
12+
env:
13+
browser: true
14+
es6: true
15+
node: true
16+
jest: true
17+
18+
plugins:
19+
- import
20+
- sonarjs
21+
22+
extends:
23+
- eslint:recommended
24+
- plugin:sonarjs/recommended
25+
- plugin:prettier/recommended
26+
27+
rules:
28+
# 0 = off, 1 = warn, 2 = error
29+
"space-before-function-paren": 0
30+
"no-useless-constructor": 0
31+
"no-undef": 2
32+
"no-console": [2, { allow: ["error", "warn", "info", "assert"] }]
33+
"comma-dangle": ["error", "only-multiline"]
34+
"no-unused-vars": 0
35+
"no-var": 2
36+
"one-var-declaration-per-line": 2
37+
"prefer-const": 2
38+
"no-const-assign": 2
39+
"no-duplicate-imports": 2
40+
"no-use-before-define": [2, { "functions": false, "classes": false }]
41+
"eqeqeq": [2, "always", { "null": "ignore" }]
42+
"no-case-declarations": 0
43+
"no-restricted-syntax":
44+
[
45+
2,
46+
{
47+
"selector": "BinaryExpression[operator=/(==|===|!=|!==)/][left.raw=true], BinaryExpression[operator=/(==|===|!=|!==)/][right.raw=true]",
48+
"message": Don't compare for equality against boolean literals,
49+
},
50+
]
51+
52+
# https://github.com/benmosher/eslint-plugin-import/pull/334
53+
"import/no-duplicates": 2
54+
"import/first": 2
55+
"import/newline-after-import": 2
56+
"import/order":
57+
[
58+
2,
59+
{
60+
"newlines-between": "always",
61+
"alphabetize": { "order": "asc" },
62+
"groups":
63+
["builtin", "external", "internal", "parent", "sibling", "index"],
64+
},
65+
]
66+
67+
"sonarjs/cognitive-complexity": 0
68+
"sonarjs/no-duplicate-string": 0
69+
"sonarjs/no-big-function": 0
70+
"sonarjs/no-identical-functions": 0
71+
"sonarjs/no-small-switch": 0
72+
73+
overrides:
74+
- files:
75+
- ./**/*.{ts,tsx}
76+
rules:
77+
"no-unused-vars":
78+
[
79+
2,
80+
{
81+
varsIgnorePattern: "^_",
82+
argsIgnorePattern: "^_",
83+
ignoreRestSiblings: true,
84+
},
85+
]
86+
87+
- files:
88+
- ./**/*{.ts,.tsx}
89+
plugins:
90+
- "@typescript-eslint"
91+
parserOptions:
92+
project: ./tsconfig.json
93+
rules:
94+
"no-undef": 0
95+
# TypeScript declare merge
96+
"no-redeclare": 0
97+
"no-useless-constructor": 0
98+
"no-unused-vars": 0
99+
"no-dupe-class-members": 0
100+
"no-case-declarations": 0
101+
"no-duplicate-imports": 0
102+
# TypeScript Interface and Type
103+
"no-use-before-define": 0
104+
105+
"@typescript-eslint/adjacent-overload-signatures": 2
106+
"@typescript-eslint/await-thenable": 2
107+
"@typescript-eslint/consistent-type-assertions": 2
108+
"@typescript-eslint/ban-types":
109+
[
110+
"error",
111+
{
112+
"types":
113+
{
114+
"String":
115+
{ "message": "Use string instead", "fixWith": "string" },
116+
"Number":
117+
{ "message": "Use number instead", "fixWith": "number" },
118+
"Boolean":
119+
{ "message": "Use boolean instead", "fixWith": "boolean" },
120+
"Function": { "message": "Use explicit type instead" },
121+
},
122+
},
123+
]
124+
"@typescript-eslint/explicit-member-accessibility":
125+
[
126+
"error",
127+
{
128+
accessibility: "explicit",
129+
overrides:
130+
{
131+
accessors: "no-public",
132+
constructors: "no-public",
133+
methods: "no-public",
134+
properties: "no-public",
135+
parameterProperties: "explicit",
136+
},
137+
},
138+
]
139+
"@typescript-eslint/method-signature-style": 2
140+
"@typescript-eslint/no-floating-promises": 2
141+
"@typescript-eslint/no-implied-eval": 2
142+
"@typescript-eslint/no-for-in-array": 2
143+
"@typescript-eslint/no-inferrable-types": 2
144+
"@typescript-eslint/no-invalid-void-type": 2
145+
"@typescript-eslint/no-misused-new": 2
146+
"@typescript-eslint/no-misused-promises": 2
147+
"@typescript-eslint/no-namespace": 2
148+
"@typescript-eslint/no-non-null-asserted-optional-chain": 2
149+
"@typescript-eslint/no-throw-literal": 2
150+
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 2
151+
"@typescript-eslint/prefer-for-of": 2
152+
"@typescript-eslint/prefer-nullish-coalescing": 2
153+
"@typescript-eslint/switch-exhaustiveness-check": 2
154+
"@typescript-eslint/prefer-optional-chain": 2
155+
"@typescript-eslint/prefer-readonly": 2
156+
"@typescript-eslint/prefer-string-starts-ends-with": 0
157+
"@typescript-eslint/no-array-constructor": 2
158+
"@typescript-eslint/require-await": 2
159+
"@typescript-eslint/return-await": 2
160+
"@typescript-eslint/ban-ts-comment":
161+
[
162+
2,
163+
{
164+
"ts-expect-error": false,
165+
"ts-ignore": true,
166+
"ts-nocheck": true,
167+
"ts-check": false,
168+
},
169+
]
170+
"@typescript-eslint/naming-convention":
171+
[
172+
2,
173+
{
174+
selector: "memberLike",
175+
format: ["camelCase", "PascalCase"],
176+
modifiers: ["private"],
177+
leadingUnderscore: "forbid",
178+
},
179+
]
180+
"@typescript-eslint/no-unused-vars":
181+
[
182+
2,
183+
{
184+
varsIgnorePattern: "^_",
185+
argsIgnorePattern: "^_",
186+
ignoreRestSiblings: true,
187+
},
188+
]
189+
"@typescript-eslint/member-ordering":
190+
[
191+
2,
192+
{
193+
default:
194+
[
195+
"public-static-field",
196+
"protected-static-field",
197+
"private-static-field",
198+
"public-static-method",
199+
"protected-static-method",
200+
"private-static-method",
201+
"public-instance-field",
202+
"protected-instance-field",
203+
"private-instance-field",
204+
"public-constructor",
205+
"protected-constructor",
206+
"private-constructor",
207+
"public-instance-method",
208+
"protected-instance-method",
209+
"private-instance-method",
210+
],
211+
},
212+
]

bindings/javascript/benches/bench.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { promises as fs } from "fs";
22
import { join } from "path";
3+
34
import b from "benny";
4-
import juice from "juice";
55
import inlineCss from "inline-css";
6+
import juice from "juice";
67

78
import { inline } from "../index";
89
import { initWasm, inline as wasmInline } from "../wasm";

bindings/javascript/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,23 @@
3737
"@swc-node/register": "^1.6.8",
3838
"@swc/core": "^1.3.101",
3939
"@types/copyfiles": "^2",
40+
"@types/eslint": "^8",
41+
"@typescript-eslint/eslint-plugin": "^6.16.0",
42+
"@typescript-eslint/parser": "^6.16.0",
4043
"ava": "^6.0.1",
4144
"benny": "^3.7.1",
4245
"copyfiles": "^2.4.1",
4346
"dts-bundle-generator": "^9.1.0",
4447
"esbuild": "^0.19.10",
48+
"eslint": "^8.56.0",
49+
"eslint-config-prettier": "^9.1.0",
50+
"eslint-plugin-import": "^2.29.1",
51+
"eslint-plugin-prettier": "^5.1.2",
52+
"eslint-plugin-sonarjs": "^0.23.0",
4553
"inline-css": "^4.0.2",
4654
"juice": "^10.0.0",
4755
"npm-run-all2": "^6.1.1",
56+
"prettier": "^3.1.1",
4857
"typescript": "^5.3.3"
4958
},
5059
"ava": {
@@ -77,6 +86,8 @@
7786
"build:wasm": "run-s build:wasm-web copy-wasm bundle",
7887
"build:wasm-web": "wasm-pack build --target web --out-name index --out-dir wasm/dist --release",
7988
"copy-wasm": "copyfiles -f wasm/dist/index_bg.wasm ./wasm",
89+
"lint": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}'",
90+
"lint:fix": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}' --fix",
8091
"prepublishOnly": "napi prepublish -t npm",
8192
"test": "ava __test__/index*.*",
8293
"test:wasm": "ava __test__/**/wasm*.*",

0 commit comments

Comments
 (0)