Comparing version 9.1.2 to 10.0.0
# Changes | ||
## 10.0.0 | ||
Switch to the new `ESLint` API, if available. The `CLIEngine` API has been | ||
deprecated. | ||
- 💥 [`ee74815`](https://github.com/mantoni/eslint_d.js/commit/ee7481526ab48f0328e02681cda6060cd5ff2085) | ||
**BREAKING:** Use ESLint class if available | ||
- 📚 [`1d6227e`](https://github.com/mantoni/eslint_d.js/commit/1d6227e247562aa12207df5c092ff43ea8660279) | ||
Add compatibility notes for v10 | ||
- 📚 [`d67e203`](https://github.com/mantoni/eslint_d.js/commit/d67e203cf6c99dc2da5b1d9fda8fcdffcfdf435e) | ||
Document ale integration and not sublime issue | ||
- 📚 [`68c4eec`](https://github.com/mantoni/eslint_d.js/commit/68c4eece628c3ba43214c651602acb10920e0cf6) | ||
Change badge | ||
- ✨ [`93dba52`](https://github.com/mantoni/eslint_d.js/commit/93dba52f70f128539c3491146c189b421a3f11f8) | ||
Remove Travis config | ||
- ✨ [`b8b9f3c`](https://github.com/mantoni/eslint_d.js/commit/b8b9f3cfc818cce156bd4662043ec125c2ba8be1) | ||
Configure GitHub actions | ||
- ✨ [`d83c9b9`](https://github.com/mantoni/eslint_d.js/commit/d83c9b90b99bbee0d43c8d813827fc8891b771f1) | ||
Fix watch script | ||
- ✨ [`e65fdb9`](https://github.com/mantoni/eslint_d.js/commit/e65fdb9771d1d87665f748d3d6eb5c08d56c35d1) | ||
Update mocha | ||
- ✨ [`06d9b71`](https://github.com/mantoni/eslint_d.js/commit/06d9b71b5436aa341e695d8b03e3a164c8fd0cf0) | ||
Upgrade referee-sinon | ||
- ✨ [`2b42e64`](https://github.com/mantoni/eslint_d.js/commit/2b42e64643bb9efe99b3cf5e803a0285785d254e) | ||
Add contributors | ||
_Released by [Maximilian Antoni](https://github.com/mantoni) on 2021-01-30._ | ||
## 9.1.2 | ||
@@ -4,0 +32,0 @@ |
@@ -0,9 +1,12 @@ | ||
/* eslint-disable no-sync */ | ||
'use strict'; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const LRU = require('nanolru'); | ||
const resolver = require('./resolver'); | ||
const options = require('./options'); | ||
const path = require('path'); | ||
const options_cliengine = require('./options-cliengine'); | ||
const options_eslint = require('./options-eslint'); | ||
function translateOptions(cliOptions, cwd) { | ||
function translateOptionsCLIEngine(cliOptions, cwd) { | ||
return { | ||
@@ -41,8 +44,45 @@ envs: cliOptions.env, | ||
function translateOptionsESLint(cliOptions, cwd) { | ||
return { | ||
allowInlineConfig: cliOptions.inlineConfig, | ||
cache: cliOptions.cache, | ||
cacheLocation: cliOptions.cacheLocation || cliOptions.cacheFile, | ||
errorOnUnmatchedPattern: cliOptions.errorOnUnmatchedPattern, | ||
extensions: cliOptions.ext, | ||
fix: (cliOptions.fix || cliOptions.fixDryRun || cliOptions.fixToStdout) | ||
&& (cliOptions.quiet ? cliOptions.quietFixPredicate : true), | ||
fixTypes: cliOptions.fixType, | ||
ignore: cliOptions.ignore, | ||
ignorePath: cliOptions.ignorePath, | ||
overrideConfig: { | ||
env: cliOptions.env && cliOptions.env.reduce((obj, name) => { | ||
obj[name] = true; | ||
return obj; | ||
}, {}), | ||
globals: cliOptions.global && cliOptions.global.reduce((obj, name) => { | ||
if (name.endsWith(':true')) { | ||
obj[name.slice(0, -5)] = 'writable'; | ||
} else { | ||
obj[name] = 'readonly'; | ||
} | ||
return obj; | ||
}, {}), | ||
ignorePatterns: cliOptions.ignorePattern, | ||
parser: cliOptions.parser, | ||
parserOptions: cliOptions.parserOptions, | ||
plugins: cliOptions.plugin, | ||
rules: cliOptions.rule | ||
}, | ||
overrideConfigFile: cliOptions.overrideConfigFile, | ||
reportUnusedDisableDirectives: cliOptions.reportUnusedDisableDirectives | ||
? 'error' : undefined, | ||
resolvePluginsRelativeTo: cliOptions.resolvePluginsRelativeTo, | ||
rulePaths: cliOptions.rulesdir, | ||
useEslintrc: cliOptions.eslintrc, | ||
cwd | ||
}; | ||
} | ||
const eslintCache = new LRU(10); | ||
function fail(message) { | ||
return `${message}\n# exit 1`; | ||
} | ||
function createCache(cwd) { | ||
@@ -73,75 +113,220 @@ let eslintPath; | ||
/* | ||
* The core_d service entry point. | ||
*/ | ||
exports.invoke = function (cwd, args, text, mtime) { | ||
process.chdir(cwd); | ||
function countErrors(results) { | ||
let errorCount = 0; | ||
let warningCount = 0; | ||
for (const result of results) { | ||
errorCount += result.errorCount; | ||
warningCount += result.warningCount; | ||
} | ||
return { errorCount, warningCount }; | ||
} | ||
let cache = eslintCache.get(cwd); | ||
if (!cache) { | ||
cache = createCache(cwd); | ||
} else if (mtime > cache.last_run) { | ||
clearRequireCache(cwd); | ||
cache = createCache(cwd); | ||
function isDirectory(filePath) { | ||
try { | ||
return fs.statSync(filePath).isDirectory(); | ||
} catch (error) { | ||
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') { | ||
return false; | ||
} | ||
throw error; | ||
} | ||
cache.last_run = Date.now(); | ||
} | ||
const currentOptions = options.parse([0, 0].concat(args)); | ||
cache.chalk.enabled = currentOptions.color; | ||
if (currentOptions.color === false) { | ||
cache.chalk.level = 0; | ||
async function printResults(engine, results, opts, callback) { | ||
const { format, outputFile } = opts; | ||
let formatter; | ||
try { | ||
formatter = await engine.loadFormatter(format); | ||
} catch (e) { | ||
callback(e.message); | ||
return; | ||
} | ||
const output = formatter.format(results); | ||
if (output) { | ||
if (outputFile) { | ||
const filePath = path.resolve(process.cwd(), outputFile); | ||
if (isDirectory(filePath)) { | ||
callback(`Cannot write to output file path, it is a directory: ${ | ||
outputFile}`); | ||
return; | ||
} | ||
try { | ||
fs.mkdirSync(path.dirname(filePath), { recursive: true }); | ||
fs.writeFileSync(filePath, output); | ||
} catch (ex) { | ||
callback(`There was a problem writing the output file:\n${ex}`); | ||
return; | ||
} | ||
} else { | ||
const { errorCount, warningCount } = countErrors(results); | ||
const tooManyWarnings | ||
= opts.maxWarnings >= 0 && warningCount > opts.maxWarnings; | ||
if (!errorCount && tooManyWarnings) { | ||
callback(`${output}\nESLint found too many warnings (maximum: ${ | ||
opts.maxWarnings}).`); | ||
return; | ||
} | ||
if (errorCount) { | ||
callback(output); | ||
return; | ||
} | ||
} | ||
} | ||
callback(null, output); | ||
} | ||
async function executeWithESLint(ESLint, cwd, opts, text, callback) { | ||
const engine = new ESLint(translateOptionsESLint(opts, cwd)); | ||
const files = opts._; | ||
const stdin = opts.stdin; | ||
if (opts.printConfig) { | ||
if (files.length !== 1) { | ||
callback( | ||
'The --print-config option must be used with exactly one file name.' | ||
); | ||
return; | ||
} | ||
if (text) { | ||
callback('The --print-config option is not available for piped-in code.'); | ||
return; | ||
} | ||
const fileConfig = await engine.calculateConfigForFile(opts.printConfig); | ||
callback(null, JSON.stringify(fileConfig, null, ' ')); | ||
return; | ||
} | ||
let results; | ||
if (stdin) { | ||
results = await engine.lintText(text, { | ||
filePath: opts.stdinFilename, | ||
warnIgnored: true | ||
}); | ||
} else { | ||
cache.chalk.level = undefined; | ||
results = await engine.lintFiles(files); | ||
} | ||
const files = currentOptions._; | ||
const stdin = currentOptions.stdin; | ||
if (!files.length && (!stdin || typeof text !== 'string')) { | ||
return `${options.generateHelp()}\n`; | ||
if (opts.fixToStdout) { | ||
// No results will be returned if the file is ignored | ||
// No output will be returned if there are no fixes | ||
callback(null, | ||
(!opts.fixDryRun && results[0] && results[0].output) || text); | ||
return; | ||
} | ||
const eslintOptions = translateOptions(currentOptions, cwd); | ||
if (opts.fix) { | ||
await ESLint.outputFixes(results); | ||
} | ||
if (opts.quiet) { | ||
results = ESLint.getErrorResults(results); | ||
} | ||
await printResults(engine, results, opts, callback); | ||
} | ||
function executeWithCLIEngine(CLIEngine, cwd, opts, text, callback) { | ||
const eslintOptions = translateOptionsCLIEngine(opts, cwd); | ||
// v4.0 API compatibility | ||
eslintOptions.cwd = path.resolve(cwd); | ||
const engine = new cache.eslint.CLIEngine(eslintOptions); | ||
if (currentOptions.printConfig) { | ||
const engine = new CLIEngine(eslintOptions); | ||
const files = opts._; | ||
const stdin = opts.stdin; | ||
if (opts.printConfig) { | ||
if (files.length !== 1) { | ||
return fail('The --print-config option requires a ' | ||
+ 'single file as positional argument.'); | ||
callback('The --print-config option requires a single file as positional ' | ||
+ 'argument.'); | ||
return; | ||
} | ||
if (text) { | ||
return fail('The --print-config option is not available for piped-in ' | ||
+ 'code.'); | ||
callback('The --print-config option is not available for piped-in code.'); | ||
return; | ||
} | ||
const fileConfig = engine.getConfigForFile(files[0]); | ||
return JSON.stringify(fileConfig, null, ' '); | ||
callback(null, JSON.stringify(fileConfig, null, ' ')); | ||
return; | ||
} | ||
if (currentOptions.fixToStdout && !stdin) { | ||
return fail('The --fix-to-stdout option must be used with --stdin.'); | ||
} | ||
let report; | ||
if (stdin) { | ||
report = engine.executeOnText(text, currentOptions.stdinFilename); | ||
report = engine.executeOnText(text, opts.stdinFilename); | ||
} else { | ||
report = engine.executeOnFiles(files); | ||
} | ||
if (currentOptions.fixToStdout) { | ||
if (opts.fixToStdout) { | ||
// No results will be returned if the file is ignored | ||
// No output will be returned if there are no fixes | ||
return (report.results[0] && report.results[0].output) || text; | ||
callback(null, (report.results[0] && report.results[0].output) || text); | ||
return; | ||
} | ||
if (currentOptions.fix) { | ||
cache.eslint.CLIEngine.outputFixes(report); | ||
if (opts.fix) { | ||
CLIEngine.outputFixes(report); | ||
} | ||
if (currentOptions.quiet) { | ||
report.results = cache.eslint.CLIEngine.getErrorResults(report.results); | ||
if (opts.quiet) { | ||
report.results = CLIEngine.getErrorResults(report.results); | ||
} | ||
const format = currentOptions.format; | ||
const format = opts.format; | ||
const formatter = engine.getFormatter(format); | ||
const output = formatter(report.results); | ||
const max_warnings = currentOptions.maxWarnings; | ||
const max_warnings = opts.maxWarnings; | ||
if (report.errorCount | ||
|| (max_warnings >= 0 && report.warningCount > max_warnings)) { | ||
return fail(output); | ||
callback(output); | ||
return; | ||
} | ||
return output; | ||
callback(null, output); | ||
} | ||
/* | ||
* The core_d service entry point. | ||
*/ | ||
exports.invoke = async function (cwd, args, text, mtime, callback) { | ||
process.chdir(cwd); | ||
let cache = eslintCache.get(cwd); | ||
if (!cache) { | ||
cache = createCache(cwd); | ||
} else if (mtime > cache.last_run) { | ||
clearRequireCache(cwd); | ||
cache = createCache(cwd); | ||
} | ||
cache.last_run = Date.now(); | ||
const opts = cache.eslint.ESLint | ||
? options_eslint.parse([0, 0].concat(args)) | ||
: options_cliengine.parse([0, 0].concat(args)); | ||
cache.chalk.enabled = opts.color; | ||
if (opts.color === false) { | ||
cache.chalk.level = 0; | ||
} else { | ||
cache.chalk.level = undefined; | ||
} | ||
const files = opts._; | ||
const stdin = opts.stdin; | ||
if (!files.length && (!stdin || typeof text !== 'string')) { | ||
callback(null, `${options_cliengine.generateHelp()}\n`); | ||
return; | ||
} | ||
if (opts.fixToStdout && !stdin) { | ||
callback('The --fix-to-stdout option must be used with --stdin.'); | ||
return; | ||
} | ||
if (cache.eslint.ESLint) { | ||
try { | ||
await executeWithESLint(cache.eslint.ESLint, cwd, opts, text, callback); | ||
} catch (e) { | ||
callback(e); | ||
} | ||
return; | ||
} | ||
try { | ||
executeWithCLIEngine(cache.eslint.CLIEngine, cwd, opts, text, callback); | ||
} catch (e) { | ||
callback(e); | ||
} | ||
}; | ||
@@ -148,0 +333,0 @@ |
{ | ||
"name": "eslint_d", | ||
"version": "9.1.2", | ||
"version": "10.0.0", | ||
"description": "Makes eslint the fastest linter on the planet", | ||
@@ -23,11 +23,16 @@ "bin": "bin/eslint_d.js", | ||
"Joseph Frazier <1212jtraceur@gmail.com>", | ||
"Sergey Markov <Mar.Ser.DLX@gmail.com>" | ||
"Sergey Markov <Mar.Ser.DLX@gmail.com>", | ||
"Alexander Koltun <alexander.koltun@gmail.com>", | ||
"Ibuki <main@fuwa.dev>" | ||
], | ||
"homepage": "https://github.com/mantoni/eslint_d.js", | ||
"eslintConfig": { | ||
"extends": "@studio" | ||
"extends": "@studio", | ||
"parserOptions": { | ||
"ecmaVersion": 2017 | ||
} | ||
}, | ||
"scripts": { | ||
"test": "mocha --file ./node_modules/mocha-referee-sinon", | ||
"watch": "mocha --watch", | ||
"watch": "npm run test -- --watch", | ||
"lint": "eslint . --ignore-pattern '**/node_modules/**'", | ||
@@ -45,3 +50,3 @@ "posttest": "npm run lint", | ||
"dependencies": { | ||
"core_d": "^2.0.0", | ||
"core_d": "^3.0.0", | ||
"eslint": "^7.3.0", | ||
@@ -59,6 +64,6 @@ "nanolru": "^1.0.0", | ||
"devDependencies": { | ||
"@sinonjs/referee-sinon": "^7.1.0", | ||
"@sinonjs/referee-sinon": "^8.0.0", | ||
"@studio/changes": "^2.0.1", | ||
"@studio/eslint-config": "^1.1.1", | ||
"mocha": "^8.1.3", | ||
"mocha": "^8.2.1", | ||
"mocha-referee-sinon": "^1.0.0", | ||
@@ -65,0 +70,0 @@ "semver": "^7.3.2" |
# eslint\_d | ||
[![Build Status]](https://travis-ci.org/mantoni/eslint_d.js) | ||
![Build Status](https://github.com/mantoni/eslint_d.js/workflows/Build/badge.svg) | ||
[![SemVer]](http://semver.org) | ||
@@ -92,10 +92,14 @@ [![License]](https://github.com/mantoni/eslint\_d.js/blob/master/LICENSE) | ||
- __Sublime__: Check out [SublimeLinter-contrib-eslint\_d][SublimeLinter]. | ||
- __Vim__: Install the [syntastic][] plugin, then make sure this is in your | ||
`.vimrc`: | ||
- __Vim__: | ||
- With [syntastic][]: | ||
```vim | ||
let g:syntastic_javascript_checkers = ['eslint'] | ||
let g:syntastic_javascript_eslint_exec = 'eslint_d' | ||
``` | ||
```vim | ||
let g:syntastic_javascript_checkers = ['eslint'] | ||
let g:syntastic_javascript_eslint_exec = 'eslint_d' | ||
``` | ||
- With [ale][]: | ||
```vim | ||
let g:ale_javascript_eslint_executable = 'eslint_d' | ||
let g:ale_javascript_eslint_use_global = 1 | ||
``` | ||
@@ -105,5 +109,2 @@ - __WebStorm__: Configure your IDE to point to the `eslint_d` package instead | ||
select your `eslint_d` package. | ||
- __Atom__: You will not gain any performance from this module as it already | ||
avoids starting a new node instance and uses the API directly (see [this | ||
AtomLinter issue](https://github.com/AtomLinter/linter-eslint/issues/215)). | ||
- __Emacs__: Use [flycheck](http://www.flycheck.org/) with the | ||
@@ -115,2 +116,7 @@ `javascript-eslint` checker: | ||
``` | ||
- __Sublime__: Check out [SublimeLinter-contrib-eslint\_d][SublimeLinter]. | ||
⚠️ Please help resolving [issue | ||
#120](https://github.com/mantoni/eslint_d.js/issues/120). | ||
- __Atom__, __VSCode__: You will not gain any performance from this module as | ||
these editors already cache eslint instances for you. | ||
@@ -173,3 +179,6 @@ If you're using `eslint_d` in any other editor, please let us know! | ||
- `9.0.0`: eslint 4.0+, 5.0+, 6.0+ and 7.0+, node 10, 12 and 14 | ||
- `10.0.0`: eslint 4.0+, 5.0+, 6.0+ and 7.0+, node 10, 12 and 14 (using new | ||
`ESLint` API if available) | ||
- `9.0.0`: eslint 4.0+, 5.0+, 6.0+ and 7.0+, node 10, 12 and 14 (using | ||
`CLIEngine` API) | ||
- `8.0.0`: eslint 4.0+, 5.0+ and 6.0+, node 8, 10 and 12 | ||
@@ -188,3 +197,2 @@ - `7.2.0`: eslint 4.0+ and 5.0+, node 6, 8 and 10 | ||
[Build Status]: https://img.shields.io/travis/mantoni/eslint_d.js/master.svg | ||
[SemVer]: https://img.shields.io/:semver-%E2%9C%93-brightgreen.svg | ||
@@ -195,2 +203,3 @@ [License]: https://img.shields.io/npm/l/eslint_d.svg | ||
[syntastic]: https://github.com/scrooloose/syntastic | ||
[ale]: https://github.com/dense-analysis/ale | ||
[change220]: https://github.com/mantoni/eslint_d.js/blob/master/CHANGES.md#220 | ||
@@ -197,0 +206,0 @@ [change401]: https://github.com/mantoni/eslint_d.js/blob/master/CHANGES.md#401 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60414
10
891
203
7
1
+ Addedcore_d@3.2.0(transitive)
+ Addedsupports-color@8.1.1(transitive)
- Removedcore_d@2.0.0(transitive)
Updatedcore_d@^3.0.0