-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: usage of ESM imports instead of CommonJS (#271)
- Loading branch information
1 parent
9f616cc
commit a11665f
Showing
8 changed files
with
98 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Special test for the oldest version of Node.js that we "support" | ||
# even though the linter won't actually run. Test that the command | ||
# line program exits cleanly. | ||
|
||
name: Old test | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [0.10.48] | ||
|
||
steps: | ||
- name: Checkout project | ||
uses: actions/[email protected] | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/[email protected] | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Cache Node dependencies | ||
uses: actions/[email protected] | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Test that the command line program exits cleanly. | ||
run: ./bin/cmd.js | ||
shell: bash |
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 |
---|---|---|
@@ -1,4 +1,16 @@ | ||
#!/usr/bin/env node | ||
/* eslint-disable no-var, no-eval */ | ||
|
||
const opts = require('../options.js') | ||
require('standard-engine').cli(opts) | ||
var match = process.version.match(/v(\d+)\.(\d+)/) | ||
var major = parseInt(match[1], 10) | ||
var minor = parseInt(match[2], 10) | ||
|
||
if (major >= 12 || (major === 12 && minor >= 20)) { | ||
eval('import("standard-engine")').then(function (standardEngine) { | ||
eval('import("../options.js")').then(function (options) { | ||
standardEngine.cli(options.default) | ||
}) | ||
}) | ||
} else { | ||
console.error('semistandard: Node 12.20.0 or greater is required. `semistandard` did not 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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/*! semistandard. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */ | ||
// programmatic usage | ||
const Linter = require('standard-engine').linter | ||
import engine from 'standard-engine' | ||
import opts from './options.js' | ||
|
||
const opts = require('./options.js') | ||
const Linter = engine.linter | ||
|
||
module.exports = new Linter(opts) | ||
export default new Linter(opts) |
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
const path = require('path') | ||
const pkg = require('./package.json') | ||
import { fileURLToPath } from 'node:url' | ||
import { readFileSync } from 'node:fs' | ||
import eslint from 'eslint' | ||
|
||
module.exports = { | ||
const pkgUrl = new URL('./package.json', import.meta.url) | ||
const pkg = JSON.parse(readFileSync(pkgUrl, 'utf-8')) | ||
|
||
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!', | ||
eslint: require('eslint'), | ||
eslint, | ||
eslintConfig: { | ||
configFile: path.join(__dirname, 'eslintrc.json') | ||
configFile: fileURLToPath(new URL('eslintrc.json', import.meta.url)) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
const path = require('path') | ||
const semistandard = require('../') | ||
const test = require('tape') | ||
const filePath = path.resolve('./bin/cmd.js') | ||
import { resolve } from 'node:path' | ||
import test from 'tape' | ||
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, 2, 'error count 2') | ||
t.equal(result.errorCount, 7, 'error count 7') | ||
|
||
t.equal(path.resolve(result.results[0].filePath), filePath, 'error filepath correct') | ||
t.equal(result.results[0].messages[0].message, 'Missing semicolon.', 'first mising semicolon message') | ||
t.equal(result.results[0].messages[0].message, 'Missing semicolon.', 'second mising semicolon message') | ||
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') | ||
}) | ||
}) |
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