Skip to content

Commit

Permalink
feat: usage of ESLint v8 (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
voxpelli committed Mar 8, 2023
1 parent a11665f commit ccec83a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 38 deletions.
11 changes: 4 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
/*! semistandard. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
// programmatic usage
import engine from 'standard-engine'
import opts from './options.js'
/*! standard. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
import { StandardEngine } from 'standard-engine'
import options from './options.js'

const Linter = engine.linter

export default new Linter(opts)
export default new StandardEngine(options)
22 changes: 12 additions & 10 deletions options.js
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": [
Expand Down Expand Up @@ -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/**"
Expand Down
29 changes: 19 additions & 10 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})

0 comments on commit ccec83a

Please sign in to comment.