Skip to content

Commit 025abfb

Browse files
committed
feat: start deno lint
1 parent a5c1e4c commit 025abfb

File tree

20 files changed

+414
-2
lines changed

20 files changed

+414
-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/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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"
12+
napi = { version = "0.4" }
13+
napi-derive = { version = "0.4" }
14+
termcolor = "1.1"
15+
16+
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
17+
jemallocator = { version = "0.3", features = ["disable_initial_exec_tls"] }
18+
19+
[build-dependencies]
20+
napi-build = { version = "0.2" }

packages/deno-lint/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `@node-rs/deno-lint`
2+
3+
> deno_lint nodejs binding
4+
5+
## Usage
6+
7+
```ts
8+
import { lint } from 'deno-lint'
9+
10+
```
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/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[]

packages/deno-lint/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const { platform } = require('os')
2+
3+
const { loadBinding } = require('@node-rs/helper')
4+
5+
let binding
6+
7+
try {
8+
binding = loadBinding(__dirname, 'deno-lint')
9+
} catch (e) {
10+
try {
11+
binding = require(`@node-rs/deno-lint-${platform()}`)
12+
} catch (e) {
13+
throw new TypeError('Not compatible with your platform. Error message: ' + e.message)
14+
}
15+
}
16+
17+
module.exports = {
18+
lint: function lint(filename, sourcecode) {
19+
const source = Buffer.isBuffer(sourcecode) ? sourcecode : Buffer.from(sourcecode)
20+
return binding.lint(filename, source)
21+
},
22+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `@node-rs/deno-lint-darwin`
2+
3+
This is the macOS 64-bit binary for `@node-rs/deno-lint`.

0 commit comments

Comments
 (0)