From ccec83ad234c2910823691b1e6a383b65f68c94d Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Wed, 8 Mar 2023 19:50:27 +0100 Subject: [PATCH] feat: usage of ESLint v8 (#274) BREAKING CHANGE: Similarly to https://github.com/standard/standard/releases/tag/v17.0.0 --- index.js | 11 ++++------- options.js | 22 ++++++++++++---------- package.json | 23 ++++++++++++----------- test/api.js | 29 +++++++++++++++++++---------- 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/index.js b/index.js index 62ac78b..f41d7ef 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,5 @@ -/*! semistandard. MIT License. Feross Aboukhadijeh */ -// programmatic usage -import engine from 'standard-engine' -import opts from './options.js' +/*! standard. MIT License. Feross Aboukhadijeh */ +import { StandardEngine } from 'standard-engine' +import options from './options.js' -const Linter = engine.linter - -export default new Linter(opts) +export default new StandardEngine(options) diff --git a/options.js b/options.js index 9c2c443..f9961cf 100644 --- a/options.js +++ b/options.js @@ -1,19 +1,21 @@ -import { fileURLToPath } from 'node:url' import { readFileSync } from 'node:fs' +import { fileURLToPath } from 'node:url' import eslint from 'eslint' -const pkgUrl = new URL('./package.json', import.meta.url) -const pkg = JSON.parse(readFileSync(pkgUrl, 'utf-8')) +// eslintConfig.overrideConfigFile have problem reading URLs and file:/// +const overrideConfigFile = fileURLToPath(new URL('./eslintrc.json', import.meta.url)) +const pkgURL = new URL('./package.json', import.meta.url) +const pkgJSON = readFileSync(pkgURL, { encoding: 'utf-8' }) +const pkg = JSON.parse(pkgJSON) export default { - // cmd, homepage, bugs all pulled from package.json - cmd: 'semistandard', - version: pkg.version, - homepage: pkg.homepage, bugs: pkg.bugs.url, - tagline: 'Semicolons For All!', + cmd: 'semistandard', eslint, eslintConfig: { - configFile: fileURLToPath(new URL('eslintrc.json', import.meta.url)) - } + overrideConfigFile + }, + homepage: pkg.homepage, + tagline: 'Semicolons For All!', + version: pkg.version } diff --git a/package.json b/package.json index 764059d..ea20937 100644 --- a/package.json +++ b/package.json @@ -14,17 +14,18 @@ "url": "https://github.com/standard/semistandard/issues" }, "dependencies": { - "eslint": "^7.32.0", - "eslint-config-semistandard": "16.0.0", - "eslint-config-standard": "16.0.3", - "eslint-config-standard-jsx": "10.0.0", - "eslint-plugin-import": "^2.24.2", - "eslint-plugin-node": "^11.1.0", - "eslint-plugin-promise": "^5.1.0", - "eslint-plugin-react": "~7.25.1", - "standard-engine": "^14.0.1" + "eslint": "^8.20.0", + "eslint-config-semistandard": "^17.0.0", + "eslint-config-standard": "17.0.0", + "eslint-config-standard-jsx": "^11.0.0", + "eslint-plugin-import": "^2.26.0", + "eslint-plugin-n": "^15.2.4", + "eslint-plugin-promise": "^6.0.0", + "eslint-plugin-react": "^7.30.1", + "standard-engine": "^15.0.0" }, "devDependencies": { + "installed-check": "^6.0.3", "merge": "^2.1.1", "mkdirp": "^1.0.4", "rimraf": "^3.0.2", @@ -33,7 +34,7 @@ "tape": "^5.3.1" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, "homepage": "https://github.com/standard/semistandard", "keywords": [ @@ -71,7 +72,7 @@ "url": "https://github.com/standard/semistandard.git" }, "scripts": { - "test": "standard && tape test/*.js" + "test": "standard && installed-check --engine-check --engine-no-dev && tape test/*.js" }, "standard": { "ignore": "tmp/**" diff --git a/test/api.js b/test/api.js index 519369e..69d96db 100644 --- a/test/api.js +++ b/test/api.js @@ -4,15 +4,24 @@ import semistandard from '../index.js' const filePath = resolve('./bin/cmd.js') -test('api usage', function (t) { - t.plan(6) - semistandard.lintFiles(['bin/cmd.js'], {}, function (err, result) { - t.error(err, 'no error while linting') - t.equal(typeof result, 'object', 'result is an object') - t.equal(result.errorCount, 7, 'error count 7') +test('api: lintFiles', async (t) => { + t.plan(5) + const [result] = await semistandard.lintFiles([filePath]) + t.equal(typeof result, 'object', 'result is an object') - t.equal(resolve(result.results[0].filePath), filePath, 'error filepath correct') - t.equal(result.results[0].messages[0].message, 'Missing semicolon.', 'first missing semicolon message') - t.equal(result.results[0].messages[0].message, 'Missing semicolon.', 'second missing semicolon message') - }) + t.equal(result.errorCount, 7, 'error count 7') + + t.equal(resolve(result.filePath), filePath, 'error filepath correct') + t.equal(result.messages[0].message, 'Missing semicolon.', 'first missing semicolon message') + t.equal(result.messages[1].message, 'Missing semicolon.', 'second missing semicolon message') +}) + +test('api: lintText', async (t) => { + t.plan(4) + const [result] = await semistandard.lintText('console.log("hi there")\n') + + t.equal(typeof result, 'object', 'result is an object') + t.equal(result.errorCount, 2, 'error count 2') + t.equal(result.messages[0].message, 'Strings must use singlequote.', 'singlequote message') + t.equal(result.messages[1].message, 'Missing semicolon.', 'missing semicolon message') })