Skip to content

Commit

Permalink
chore: Run ESLint
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Dec 28, 2023
1 parent b93461e commit 4ad1787
Show file tree
Hide file tree
Showing 6 changed files with 1,848 additions and 31 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ jobs:
- run: pip install pre-commit
- run: SKIP=fmt,cargo-check,clippy pre-commit run --all-files

eslint:
name: ESLint
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Cache NPM dependencies
uses: actions/cache@v3
with:
path: node_modules
key: npm-cache-lint-node@16-${{ hashFiles('yarn.lock') }}
working-directory: ./bindings/javascript

- name: "Install dependencies"
run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
working-directory: ./bindings/javascript

- name: ESLint
run: yarn lint
working-directory: ./bindings/javascript

test-stable:
name: Test (stable)
runs-on: ubuntu-22.04
Expand Down
5 changes: 5 additions & 0 deletions bindings/javascript/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
js-binding.js
js-binding.d.ts
target
wasm
wasm/dist
212 changes: 212 additions & 0 deletions bindings/javascript/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
parser: "@typescript-eslint/parser"

parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: latest
sourceType: module

globals:
Deno: readonly

env:
browser: true
es6: true
node: true
jest: true

plugins:
- import
- sonarjs

extends:
- eslint:recommended
- plugin:sonarjs/recommended
- plugin:prettier/recommended

rules:
# 0 = off, 1 = warn, 2 = error
"space-before-function-paren": 0
"no-useless-constructor": 0
"no-undef": 2
"no-console": [2, { allow: ["error", "warn", "info", "assert"] }]
"comma-dangle": ["error", "only-multiline"]
"no-unused-vars": 0
"no-var": 2
"one-var-declaration-per-line": 2
"prefer-const": 2
"no-const-assign": 2
"no-duplicate-imports": 2
"no-use-before-define": [2, { "functions": false, "classes": false }]
"eqeqeq": [2, "always", { "null": "ignore" }]
"no-case-declarations": 0
"no-restricted-syntax":
[
2,
{
"selector": "BinaryExpression[operator=/(==|===|!=|!==)/][left.raw=true], BinaryExpression[operator=/(==|===|!=|!==)/][right.raw=true]",
"message": Don't compare for equality against boolean literals,
},
]

# https://github.com/benmosher/eslint-plugin-import/pull/334
"import/no-duplicates": 2
"import/first": 2
"import/newline-after-import": 2
"import/order":
[
2,
{
"newlines-between": "always",
"alphabetize": { "order": "asc" },
"groups":
["builtin", "external", "internal", "parent", "sibling", "index"],
},
]

"sonarjs/cognitive-complexity": 0
"sonarjs/no-duplicate-string": 0
"sonarjs/no-big-function": 0
"sonarjs/no-identical-functions": 0
"sonarjs/no-small-switch": 0

overrides:
- files:
- ./**/*.{ts,tsx}
rules:
"no-unused-vars":
[
2,
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
]

- files:
- ./**/*{.ts,.tsx}
plugins:
- "@typescript-eslint"
parserOptions:
project: ./tsconfig.json
rules:
"no-undef": 0
# TypeScript declare merge
"no-redeclare": 0
"no-useless-constructor": 0
"no-unused-vars": 0
"no-dupe-class-members": 0
"no-case-declarations": 0
"no-duplicate-imports": 0
# TypeScript Interface and Type
"no-use-before-define": 0

"@typescript-eslint/adjacent-overload-signatures": 2
"@typescript-eslint/await-thenable": 2
"@typescript-eslint/consistent-type-assertions": 2
"@typescript-eslint/ban-types":
[
"error",
{
"types":
{
"String":
{ "message": "Use string instead", "fixWith": "string" },
"Number":
{ "message": "Use number instead", "fixWith": "number" },
"Boolean":
{ "message": "Use boolean instead", "fixWith": "boolean" },
"Function": { "message": "Use explicit type instead" },
},
},
]
"@typescript-eslint/explicit-member-accessibility":
[
"error",
{
accessibility: "explicit",
overrides:
{
accessors: "no-public",
constructors: "no-public",
methods: "no-public",
properties: "no-public",
parameterProperties: "explicit",
},
},
]
"@typescript-eslint/method-signature-style": 2
"@typescript-eslint/no-floating-promises": 2
"@typescript-eslint/no-implied-eval": 2
"@typescript-eslint/no-for-in-array": 2
"@typescript-eslint/no-inferrable-types": 2
"@typescript-eslint/no-invalid-void-type": 2
"@typescript-eslint/no-misused-new": 2
"@typescript-eslint/no-misused-promises": 2
"@typescript-eslint/no-namespace": 2
"@typescript-eslint/no-non-null-asserted-optional-chain": 2
"@typescript-eslint/no-throw-literal": 2
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 2
"@typescript-eslint/prefer-for-of": 2
"@typescript-eslint/prefer-nullish-coalescing": 2
"@typescript-eslint/switch-exhaustiveness-check": 2
"@typescript-eslint/prefer-optional-chain": 2
"@typescript-eslint/prefer-readonly": 2
"@typescript-eslint/prefer-string-starts-ends-with": 0
"@typescript-eslint/no-array-constructor": 2
"@typescript-eslint/require-await": 2
"@typescript-eslint/return-await": 2
"@typescript-eslint/ban-ts-comment":
[
2,
{
"ts-expect-error": false,
"ts-ignore": true,
"ts-nocheck": true,
"ts-check": false,
},
]
"@typescript-eslint/naming-convention":
[
2,
{
selector: "memberLike",
format: ["camelCase", "PascalCase"],
modifiers: ["private"],
leadingUnderscore: "forbid",
},
]
"@typescript-eslint/no-unused-vars":
[
2,
{
varsIgnorePattern: "^_",
argsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
]
"@typescript-eslint/member-ordering":
[
2,
{
default:
[
"public-static-field",
"protected-static-field",
"private-static-field",
"public-static-method",
"protected-static-method",
"private-static-method",
"public-instance-field",
"protected-instance-field",
"private-instance-field",
"public-constructor",
"protected-constructor",
"private-constructor",
"public-instance-method",
"protected-instance-method",
"private-instance-method",
],
},
]
3 changes: 2 additions & 1 deletion bindings/javascript/benches/bench.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { promises as fs } from "fs";
import { join } from "path";

import b from "benny";
import juice from "juice";
import inlineCss from "inline-css";
import juice from "juice";

import { inline } from "../index";
import { initWasm, inline as wasmInline } from "../wasm";
Expand Down
11 changes: 11 additions & 0 deletions bindings/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,23 @@
"@swc-node/register": "^1.6.8",
"@swc/core": "^1.3.101",
"@types/copyfiles": "^2",
"@types/eslint": "^8",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"ava": "^6.0.1",
"benny": "^3.7.1",
"copyfiles": "^2.4.1",
"dts-bundle-generator": "^9.1.0",
"esbuild": "^0.19.10",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-sonarjs": "^0.23.0",
"inline-css": "^4.0.2",
"juice": "^10.0.0",
"npm-run-all2": "^6.1.1",
"prettier": "^3.1.1",
"typescript": "^5.3.3"
},
"ava": {
Expand Down Expand Up @@ -77,6 +86,8 @@
"build:wasm": "run-s build:wasm-web copy-wasm bundle",
"build:wasm-web": "wasm-pack build --target web --out-name index --out-dir wasm/dist --release",
"copy-wasm": "copyfiles -f wasm/dist/index_bg.wasm ./wasm",
"lint": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}'",
"lint:fix": "eslint . -c ./.eslintrc.yml './**/*.{ts,tsx,js}' --fix",
"prepublishOnly": "napi prepublish -t npm",
"test": "ava __test__/index*.*",
"test:wasm": "ava __test__/**/wasm*.*",
Expand Down
Loading

0 comments on commit 4ad1787

Please sign in to comment.