Skip to content

Commit 7cd17ff

Browse files
authored
Merge pull request #61 from napi-rs/deno-lint
feat: deno lint [skip ci]
2 parents 4fbd9b8 + a2d789f commit 7cd17ff

27 files changed

+776
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
members = [
33
"./packages/bcrypt",
44
"./packages/crc32",
5+
"./packages/deno-lint",
56
"./packages/jieba"
67
]
78

packages/bcrypt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"scripts": {
2525
"bench": "cross-env NODE_ENV=production node benchmark/bcrypt.js",
2626
"build": "napi --release ./bcrypt",
27-
"build:debug": "napi ./bcrypt.debug"
27+
"build:debug": "napi ./bcrypt"
2828
},
2929
"bugs": {
3030
"url": "https://github.com/napi-rs/node-rs/issues"

packages/crc32/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"scripts": {
2525
"bench": "cross-env NODE_ENV=production node benchmark/crc32.js",
2626
"build": "napi --release ./crc32",
27-
"build:debug": "napi ./index"
27+
"build:debug": "napi ./crc32"
2828
},
2929
"bugs": {
3030
"url": "https://github.com/napi-rs/node-rs/issues"

packages/deno-lint/.defaultignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

packages/deno-lint/Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "deno-lint"
3+
version = "0.1.0"
4+
authors = ["LongYinan <[email protected]>"]
5+
edition = "2018"
6+
7+
[lib]
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
deno_lint = "0.1.22"
12+
ignore = "0.4"
13+
napi = { version = "0.4" }
14+
napi-derive = { version = "0.4" }
15+
serde = "1"
16+
serde_json = "1"
17+
termcolor = "1.1"
18+
19+
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
20+
jemallocator = { version = "0.3", features = ["disable_initial_exec_tls"] }
21+
22+
[build-dependencies]
23+
napi-build = { version = "0.2" }

packages/deno-lint/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# `@node-rs/deno-lint`
2+
3+
![](https://github.com/napi-rs/node-rs/workflows/CI/badge.svg)
4+
![](https://img.shields.io/npm/dm/@node-rs/deno-lint.svg?sanitize=true)
5+
6+
> deno_lint nodejs binding
7+
8+
## Performance
9+
10+
### Hardware info
11+
12+
```
13+
Model Name: MacBook Pro
14+
Model Identifier: MacBookPro15,1
15+
Processor Name: 6-Core Intel Core i9
16+
Processor Speed: 2.9 GHz
17+
Number of Processors: 1
18+
Total Number of Cores: 6
19+
L2 Cache (per Core): 256 KB
20+
L3 Cache: 12 MB
21+
Hyper-Threading Technology: Enabled
22+
Memory: 32 GB
23+
```
24+
25+
### Benchmark
26+
27+
```
28+
@node-rs/deno-lint x 885 ops/sec ±1.26% (92 runs sampled)
29+
eslint x 118 ops/sec ±4.97% (78 runs sampled)
30+
Lint benchmark bench suite: Fastest is @node-rs/deno-lint
31+
```
32+
33+
## Usage
34+
35+
```ts
36+
import { lint } from '@node-rs/deno-lint'
37+
38+
lint(filepath, source, enableAllRules)
39+
```
40+
41+
## webpack-loader
42+
43+
```js
44+
// webpack.config.js
45+
46+
module.exports = {
47+
module: {
48+
rules: [
49+
{
50+
enforce: 'pre',
51+
test: /\.(t|j)s?$/,
52+
loader: '@node-rs/deno-lint/webpack-loader',
53+
exclude: [/node_modules/],
54+
},
55+
],
56+
},
57+
}
58+
```
59+
60+
### Options
61+
62+
You can pass denolint options using standard webpack loader options.
63+
64+
#### `enableAllRules`
65+
66+
- Type: `Boolean`
67+
- Default: `false`
68+
69+
Whether to enable all rules. If false, `denolint` will enable all recommend rules.
70+
71+
#### `failOnError`
72+
73+
- Type: `Boolean`
74+
- Default: `false`
75+
76+
Will cause the module build to fail if there are any errors, if option is set to `true`.
77+
78+
#### `quiet`
79+
80+
- Type: `Boolean`
81+
- Default: `false`
82+
83+
Emit nothing even if there were errors happened.
84+
85+
## `denolint` cli
86+
87+
### usage
88+
89+
`npx denolint`
90+
91+
### `--all`, `-a`
92+
93+
Enable all rules flag, if not present, denolint will run with recommend rules.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { readFileSync } = require('fs')
2+
3+
const { parseForESLint } = require('@typescript-eslint/parser')
4+
const { Suite } = require('benchmark')
5+
const chalk = require('chalk')
6+
const { Linter, SourceCode } = require('eslint')
7+
8+
const { lint } = require('../index')
9+
10+
const suite = new Suite('Lint benchmark')
11+
12+
const filepath = require.resolve('rxjs/src/internal/Subscriber.ts')
13+
14+
const tsconfigPath = require.resolve('rxjs/src/tsconfig.json')
15+
16+
const sourceCodeBuffer = readFileSync(filepath)
17+
const sourcecode = sourceCodeBuffer.toString('utf-8')
18+
19+
const linter = new Linter()
20+
21+
suite
22+
.add('@node-rs/deno-lint', () => {
23+
lint(filepath, sourceCodeBuffer)
24+
})
25+
.add('eslint', () => {
26+
const parseForESLintResult = parseForESLint(sourcecode, {
27+
filePath: filepath,
28+
sourceType: 'module',
29+
ecmaVersion: 2019,
30+
project: tsconfigPath,
31+
loc: true,
32+
range: true,
33+
tokens: true,
34+
comment: true,
35+
})
36+
37+
const sc = new SourceCode({
38+
text: sourcecode,
39+
...parseForESLintResult,
40+
})
41+
42+
linter.verify(sc, {}, filepath)
43+
})
44+
.on('cycle', function (event) {
45+
console.info(String(event.target))
46+
})
47+
.on('complete', function () {
48+
console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`)
49+
})
50+
.run()

packages/deno-lint/bin.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
3+
const { binding } = require('@node-rs/deno-lint')
4+
5+
const enableAllRules = process.argv.includes('--all') || process.argv.includes('-a')
6+
7+
const hasError = binding.denolint(__dirname, enableAllRules)
8+
9+
if (hasError) {
10+
process.exit(1)
11+
}

packages/deno-lint/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate napi_build;
2+
3+
fn main() {
4+
napi_build::setup();
5+
}

packages/deno-lint/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function lint(filename: string, source: string | Buffer): string[]

0 commit comments

Comments
 (0)