-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5c1e4c
commit 025abfb
Showing
20 changed files
with
414 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
members = [ | ||
"./packages/bcrypt", | ||
"./packages/crc32", | ||
"./packages/deno-lint", | ||
"./packages/jieba" | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "deno-lint" | ||
version = "0.1.0" | ||
authors = ["LongYinan <lynweklm@gmail.com>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
deno_lint = "0.1" | ||
napi = { version = "0.4" } | ||
napi-derive = { version = "0.4" } | ||
termcolor = "1.1" | ||
|
||
[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies] | ||
jemallocator = { version = "0.3", features = ["disable_initial_exec_tls"] } | ||
|
||
[build-dependencies] | ||
napi-build = { version = "0.2" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# `@node-rs/deno-lint` | ||
|
||
> deno_lint nodejs binding | ||
## Usage | ||
|
||
```ts | ||
import { lint } from 'deno-lint' | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { readFileSync } = require('fs') | ||
|
||
const { parseForESLint } = require('@typescript-eslint/parser') | ||
const { Suite } = require('benchmark') | ||
const chalk = require('chalk') | ||
const { Linter, SourceCode } = require('eslint') | ||
|
||
const { lint } = require('../index') | ||
|
||
const suite = new Suite('Lint benchmark') | ||
|
||
const filepath = require.resolve('rxjs/src/internal/Subscriber.ts') | ||
|
||
const tsconfigPath = require.resolve('rxjs/src/tsconfig.json') | ||
|
||
const sourceCodeBuffer = readFileSync(filepath) | ||
const sourcecode = sourceCodeBuffer.toString('utf-8') | ||
|
||
const linter = new Linter() | ||
|
||
suite | ||
.add('@node-rs/deno-lint', () => { | ||
lint(filepath, sourceCodeBuffer) | ||
}) | ||
.add('eslint', () => { | ||
const parseForESLintResult = parseForESLint(sourcecode, { | ||
filePath: filepath, | ||
sourceType: 'module', | ||
ecmaVersion: 2019, | ||
project: tsconfigPath, | ||
loc: true, | ||
range: true, | ||
tokens: true, | ||
comment: true, | ||
}) | ||
|
||
const sc = new SourceCode({ | ||
text: sourcecode, | ||
...parseForESLintResult, | ||
}) | ||
|
||
linter.verify(sc, {}, filepath) | ||
}) | ||
.on('cycle', function (event) { | ||
console.info(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
console.info(`${this.name} bench suite: Fastest is ${chalk.green(this.filter('fastest').map('name'))}`) | ||
}) | ||
.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate napi_build; | ||
|
||
fn main() { | ||
napi_build::setup(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export function lint(filename: string, source: string | Buffer): string[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { platform } = require('os') | ||
|
||
const { loadBinding } = require('@node-rs/helper') | ||
|
||
let binding | ||
|
||
try { | ||
binding = loadBinding(__dirname, 'deno-lint') | ||
} catch (e) { | ||
try { | ||
binding = require(`@node-rs/deno-lint-${platform()}`) | ||
} catch (e) { | ||
throw new TypeError('Not compatible with your platform. Error message: ' + e.message) | ||
} | ||
} | ||
|
||
module.exports = { | ||
lint: function lint(filename, sourcecode) { | ||
const source = Buffer.isBuffer(sourcecode) ? sourcecode : Buffer.from(sourcecode) | ||
return binding.lint(filename, source) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `@node-rs/deno-lint-darwin` | ||
|
||
This is the macOS 64-bit binary for `@node-rs/deno-lint`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@node-rs/deno-lint-darwin", | ||
"version": "0.0.0", | ||
"description": "Deno lint binding for NodeJS", | ||
"keywords": ["Deno", "Lint", "ESLint", "node-rs", "napi", "N-API", "Rust", "napi-rs"], | ||
"author": "LongYinan <lynweklm@gmail.com>", | ||
"homepage": "https://github.com/napi-rs/node-rs", | ||
"license": "MIT", | ||
"main": "deno-lint.darwin.node", | ||
"files": ["deno-lint.darwin.node"], | ||
"os": ["darwin"], | ||
"cpu": ["x64"], | ||
"engines": { | ||
"node": ">= 8.9" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/napi-rs/node-rs.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `@node-rs/deno-lint-linux` | ||
|
||
This is the Linux 64-bit binary for `@node-rs/deno-lint`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@node-rs/deno-lint-linux", | ||
"version": "0.0.0", | ||
"description": "Deno lint binding for NodeJS", | ||
"keywords": ["Deno", "Lint", "ESLint", "node-rs", "napi", "N-API", "Rust", "napi-rs"], | ||
"author": "LongYinan <lynweklm@gmail.com>", | ||
"homepage": "https://github.com/napi-rs/node-rs", | ||
"license": "MIT", | ||
"main": "deno-lint.linux.node", | ||
"files": ["deno-lint.linux.node"], | ||
"os": ["linux"], | ||
"cpu": ["x64"], | ||
"engines": { | ||
"node": ">= 8.9" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/napi-rs/node-rs.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# `@node-rs/deno-lint-win32` | ||
|
||
This is the Windows 64-bit binary for `@node-rs/deno-lint`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@node-rs/deno-lint-win32", | ||
"version": "0.0.0", | ||
"description": "Deno lint binding for NodeJS", | ||
"keywords": ["Deno", "Lint", "ESLint", "node-rs", "napi", "N-API", "Rust", "napi-rs"], | ||
"author": "LongYinan <lynweklm@gmail.com>", | ||
"homepage": "https://github.com/napi-rs/node-rs", | ||
"license": "MIT", | ||
"main": "deno-lint.win32.node", | ||
"files": ["deno-lint.win32.node"], | ||
"os": ["win32"], | ||
"cpu": ["x64"], | ||
"engines": { | ||
"node": ">= 8.9" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/napi-rs/node-rs.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@node-rs/deno-lint", | ||
"version": "0.0.0", | ||
"description": "Deno lint binding for NodeJS", | ||
"keywords": ["Deno", "Lint", "ESLint", "node-rs", "napi", "N-API", "Rust", "napi-rs"], | ||
"author": "LongYinan <lynweklm@gmail.com>", | ||
"homepage": "https://github.com/napi-rs/node-rs", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"typings": "index.d.ts", | ||
"files": ["index.js", "index.d.ts", "LICENSE"], | ||
"os": ["darwin", "linux", "win32"], | ||
"cpu": ["x64"], | ||
"engines": { | ||
"node": ">= 8.9" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org/", | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/napi-rs/node-rs.git" | ||
}, | ||
"scripts": { | ||
"bench": "cross-env NODE_ENV=production node benchmark/lint.js", | ||
"build": "napi --release ./deno-lint", | ||
"build:debug": "napi ./deno-lint", | ||
"prepublishOnly": "node ./publish.js", | ||
"version": "node ./version.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/napi-rs/node-rs/issues" | ||
}, | ||
"dependencies": { | ||
"@node-rs/helper": "^0.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { execSync } = require('child_process') | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const platforms = require('../../scripts/platforms') | ||
|
||
const { version } = require('./package.json') | ||
const updatePackageJson = require('./update-package') | ||
|
||
updatePackageJson(path.join(__dirname, 'package.json'), { | ||
optionalDependencies: platforms.reduce((acc, cur) => { | ||
acc[`@node-rs/deno-lint-${cur}`] = `^${version}` | ||
return acc | ||
}, {}), | ||
}) | ||
|
||
for (const name of platforms) { | ||
const pkgDir = path.join(__dirname, 'npm', name) | ||
const filename = `deno-lint.${name}.node` | ||
const bindingFile = fs.readFileSync(path.join(__dirname, `bindings-${name}`, filename)) | ||
fs.writeFileSync(path.join(pkgDir, filename), bindingFile) | ||
execSync('npm publish', { | ||
cwd: pkgDir, | ||
env: process.env, | ||
stdio: 'inherit', | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { readFileSync } = require('fs') | ||
|
||
const { lint } = require('./index') | ||
|
||
const filepath = require.resolve('rxjs/src/internal/Subscriber.ts') | ||
|
||
const sourceCodeBuffer = readFileSync(filepath) | ||
|
||
const result = lint(filepath, sourceCodeBuffer) | ||
|
||
console.assert(Array.isArray(result)) | ||
console.info('deno-lint simple test passed') |
Oops, something went wrong.