Skip to content

Commit

Permalink
Use ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed May 5, 2021
1 parent a724d25 commit 77402f1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
yarn.lock
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
coverage/
*.json
*.md
13 changes: 6 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use strict'
import {statistics} from 'vfile-statistics'

const statistics = require('vfile-statistics')

module.exports = (vfiles) =>
vfiles.map((vfile) => {
export function toESLint(vfiles) {
return vfiles.map((vfile) => {
const stats = statistics(vfile)

return {
Expand All @@ -15,12 +13,13 @@ module.exports = (vfiles) =>
ruleId: [x.source, x.ruleId].filter(Boolean).join(':') || null,
line: x.line,
column: x.column,
endLine: x.location.end.line,
endColumn: x.location.end.column,
endLine: x.position.end.line,
endColumn: x.position.end.column,
message: x.reason
}
}),
errorCount: stats.fatal,
warningCount: stats.nonfatal
}
})
}
27 changes: 10 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,27 @@
"files": [
"index.js"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"dependencies": {
"vfile-statistics": "^1.1.1"
"vfile-statistics": "^2.0.0"
},
"devDependencies": {
"nyc": "^15.0.0",
"c8": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"tape": "^5.0.0",
"vfile": "^4.0.0",
"xo": "^0.38.0"
"vfile": "^5.0.0",
"xo": "^0.39.0"
},
"scripts": {
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov node test.js",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
},
"nyc": {
"check-coverage": true,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
Expand All @@ -63,11 +60,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"esnext": false,
"rules": {
"unicorn/prefer-optional-catch-binding": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Expand Down
20 changes: 14 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ this module to display it using an ESLint formatter.

## Install

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c):
Node 12+ is needed to use it and it must be `import`ed instead of `require`d.

[npm][]:

```sh
Expand All @@ -25,19 +28,24 @@ npm install vfile-to-eslint
## Use

```js
const remark = require('remark')
const recommended = require('remark-preset-lint-recommended')
const eslintFormatterPretty = require('eslint-formatter-pretty')
const vfileToEslint = require('vfile-to-eslint')
import remark from 'remark'
import recommended from 'remark-preset-lint-recommended'
import eslintFormatterPretty from 'eslint-formatter-pretty'
import {toESLint} from 'vfile-to-eslint'

const file = remark()
.use(recommended)
.processSync('## Hello world!')

console.log(eslintFormatterPretty(vfileToEslint([file])))
console.log(eslintFormatterPretty(toESLint([file])))
```

### `vfileToEslint(files)`
## API

This package exports the following identifiers: `toESLint`.
There is no default export.

### `toESLint(files)`

Returns an `Object` that can be passed directly to an
[ESLint formatter][eslint-formatter].
Expand Down
14 changes: 7 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var test = require('tape')
var vfile = require('vfile')
var toEslint = require('.')
import test from 'tape'
import {VFile} from 'vfile'
import {toESLint} from './index.js'

test('vfile-to-eslint', function (t) {
var file = vfile({path: '~/example.md'})
test('toESLint', (t) => {
const file = new VFile({path: '~/example.md'})

file.info('This is perfect', {line: 5, column: 3}, 'alpha:bravo')

Expand All @@ -21,9 +21,9 @@ test('vfile-to-eslint', function (t) {
end: {line: 2, column: 8}
}
})
} catch (_) {}
} catch {}

t.deepEqual(toEslint([file]), [
t.deepEqual(toESLint([file]), [
{
filePath: '~/example.md',
messages: [
Expand Down

0 comments on commit 77402f1

Please sign in to comment.