Skip to content

Commit 35a93ec

Browse files
authored
Deno lint upgrade (#502)
* feat(deno-lint): upgrade to [email protected], use deno_ast * chore: dependencies upgrade
1 parent 110abb8 commit 35a93ec

22 files changed

+822
-459
lines changed

.denolint.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"rules": {
3+
"tags": [
4+
"recommended"
5+
],
6+
"exclude": [
7+
"no-explicit-any",
8+
"camelcase",
9+
"ban-unknown-rule-code",
10+
"no-window-prefix",
11+
"no-empty-interface",
12+
"ban-types",
13+
"ban-untagged-todo",
14+
"no-unused-vars",
15+
"ban-ts-comment",
16+
"no-case-declarations",
17+
"no-this-alias"
18+
]
19+
}
20+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"devDependencies": {
2525
"@napi-rs/cli": "^1.3.1",
2626
"@swc-node/register": "^1.3.4",
27-
"@typescript-eslint/eslint-plugin": "^4.30.0",
28-
"@typescript-eslint/parser": "^4.30.0",
27+
"@typescript-eslint/eslint-plugin": "^4.31.0",
28+
"@typescript-eslint/parser": "^4.31.0",
2929
"ava": "^3.15.0",
3030
"benchmark": "^2.1.4",
3131
"codecov": "^3.8.3",

packages/bcrypt/simple-test.js

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

packages/crc32/simple-test.js

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

packages/deno-lint/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cli.js
2+
cli.d.ts
3+
cli.js.map

packages/deno-lint/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ crate-type = ["cdylib"]
99

1010
[dependencies]
1111
annotate-snippets = {version = "0.9", features = ["color"]}
12-
ast_view = {version = "0.33.1", package = "dprint-swc-ecma-ast-view"}
13-
deno_lint = "=0.14.0"
12+
anyhow = "1"
13+
deno_ast = "0.1"
14+
deno_lint = "0.15"
15+
env_logger = "0.9"
16+
globwalk = "0.8"
1417
ignore = "0.4"
1518
napi = {version = "1", features = ["serde-json"]}
1619
napi-derive = "1"
1720
serde = "1"
1821
serde_json = "1"
19-
swc_ecmascript = {version = "=0.61.0", features = ["parser", "transforms", "utils", "visit"]}
2022

2123
[target.'cfg(all(target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
2224
mimalloc = {version = "0.1"}

packages/deno-lint/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ Emit nothing even if there were errors happened.
105105

106106
`npx denolint`
107107

108-
### `--all`, `-a`
108+
### `--config`, `-c`
109+
110+
Config path relative to the lint path. Config file must be a JSON file:
111+
112+
Example:
113+
114+
```json
115+
{
116+
"rules": {
117+
"tags": ["recommended"],
118+
"exclude": [
119+
"no-explicit-any",
120+
"ban-unknown-rule-code",
121+
"no-window-prefix",
122+
"no-empty-interface",
123+
"ban-types",
124+
"ban-untagged-todo",
125+
"no-unused-vars",
126+
"ban-ts-comment",
127+
"no-case-declarations",
128+
"no-this-alias"
129+
]
130+
}
131+
}
132+
```
109133

110-
Enable all rules flag, if not present, denolint will run with recommend rules.
134+
Checkout [deno_lint rules](https://github.com/denoland/deno_lint/tree/main/docs/rules) for all rules.

packages/deno-lint/benchmark/lint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ suite
2626
const parseForESLintResult = parseForESLint(sourcecode, {
2727
filePath: filepath,
2828
sourceType: 'module',
29-
ecmaVersion: 2019,
29+
ecmaVersion: 2020,
3030
project: tsconfigPath,
3131
loc: true,
3232
range: true,

packages/deno-lint/bin.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/usr/bin/env node
22

3-
const { binding } = require('@node-rs/deno-lint')
3+
const { cli } = require('./cli')
44

5-
const { argv } = process
6-
7-
const enableAllRules = argv.includes('--all') || argv.includes('-a')
8-
9-
const hasError = binding.denolint(__dirname, enableAllRules)
10-
11-
if (hasError) {
12-
process.exit(1)
13-
}
5+
cli
6+
.run(process.argv.slice(2), {
7+
stdin: process.stdin,
8+
stdout: process.stdout,
9+
stderr: process.stderr,
10+
})
11+
.then((code) => {
12+
if (code !== 0) {
13+
process.exit(code)
14+
}
15+
})
16+
.catch((e) => {
17+
console.error(e)
18+
process.exit(1)
19+
})

packages/deno-lint/cli.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { denolint } from '@node-rs/deno-lint'
2+
import { Cli, Command, Option } from 'clipanion'
3+
4+
class LintCommand extends Command {
5+
static usage = {
6+
description: 'deno lint [options] [path]',
7+
}
8+
9+
private readonly cwd = Option.String({ required: false })
10+
11+
private readonly configPath = Option.String('-c,--config', { required: false })
12+
13+
private readonly checkOnly = Option.Boolean('--check-only', { required: false })
14+
15+
execute() {
16+
const hasError = denolint(this.cwd ?? __dirname, this.configPath ?? '.denolint.json')
17+
return Promise.resolve(hasError && !this.checkOnly ? 1 : 0)
18+
}
19+
}
20+
21+
export const cli = new Cli({
22+
binaryLabel: 'deno-lint',
23+
binaryVersion: require('./package.json').version,
24+
})
25+
26+
cli.register(LintCommand)

0 commit comments

Comments
 (0)