Skip to content

Commit

Permalink
fix: incorrect vfile usage for retext rule (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin authored Sep 7, 2022
1 parent a1802d9 commit 2a999ec
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 440 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-birds-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-text": patch
---

fix: incorrect vfile usage for retext rule
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@
"@1stg/app-config": "^7.2.1",
"@1stg/lib-config": "^10.2.1",
"@changesets/changelog-github": "^0.4.6",
"@changesets/cli": "^2.24.3",
"@changesets/cli": "^2.24.4",
"@markuplint/rule-textlint": "^2.5.5",
"@pkgr/webpack": "^3.4.0",
"@pkgr/webpack-mdx": "^2.2.0",
"@textlint/textlint-plugin-markdown": "^12.2.1",
"@textlint/textlint-plugin-text": "^12.2.1",
"@types/eslint": "^8.4.6",
"@types/htmlhint": "^1.1.2",
"@types/jest": "^28.1.8",
"@types/node": "^18.7.13",
"@types/react": "^18.0.17",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.15",
"@types/react": "^18.0.18",
"@types/react-dom": "^18.0.6",
"@types/web": "^0.0.72",
"dictionary-en": "^3.2.0",
"github-markdown-css": "^5.1.0",
"jest": "^29.0.1",
"jest": "^29.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/htm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint": ">=5.0.0"
},
"dependencies": {
"eslint-plugin-utils": "^0.3.1",
"eslint-plugin-utils": "^0.3.2",
"htmlhint": "^1.1.4",
"tslib": "^2.4.0"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/markup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
},
"dependencies": {
"cosmiconfig": "^7.0.1",
"eslint-plugin-utils": "^0.3.1",
"markuplint": "^2.10.0",
"synckit": "^0.8.1",
"eslint-plugin-utils": "^0.3.2",
"markuplint": "^2.10.1",
"synckit": "^0.8.4",
"tslib": "^2.4.0"
},
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
},
"dependencies": {
"cosmiconfig": "^7.0.1",
"eslint-plugin-utils": "^0.3.1",
"eslint-plugin-utils": "^0.3.2",
"retext-stringify": "^3.1.0",
"synckit": "^0.8.1",
"synckit": "^0.8.4",
"textlint": "^12.2.1",
"tslib": "^2.4.0",
"unified": "^10.1.2",
Expand Down
1 change: 0 additions & 1 deletion packages/text/src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './retext'
export * from './textlint'
export * from './types'
11 changes: 4 additions & 7 deletions packages/text/src/rules/retext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Rule } from 'eslint'
import { JsonMessage } from 'eslint-plugin-utils'

import { lint } from '../sync'

import { RetextLintMessage } from './types'

export const retext: Rule.RuleModule = {
meta: {
type: 'problem',
Expand All @@ -22,7 +21,6 @@ export const retext: Rule.RuleModule = {
let fixed = 0

for (const {
source,
reason,
ruleId,
fatal,
Expand All @@ -41,10 +39,9 @@ export const retext: Rule.RuleModule = {
continue
}

const message: RetextLintMessage = {
reason,
source,
ruleId,
const message: JsonMessage = {
message: reason,
ruleId: ruleId!,
severity,
}
context.report({
Expand Down
4 changes: 3 additions & 1 deletion packages/text/src/rules/textlint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Rule } from 'eslint'
import { JsonMessage } from 'eslint-plugin-utils'

import { lint } from '../sync'

Expand All @@ -21,8 +22,9 @@ export const textlint: Rule.RuleModule = {
if (severity === 0) {
continue
}
const msg: JsonMessage = { severity, message, ruleId }
context.report({
message: JSON.stringify({ severity, message, ruleId }),
message: JSON.stringify(msg),
loc,
fix: fix && (() => fix as Rule.Fix),
})
Expand Down
8 changes: 0 additions & 8 deletions packages/text/src/rules/types.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/text/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ runAsWorker(
const processor = await getRetextProcessor(filename, ignoreRetextConfig)

const { VFile } = await loadEsmModule<typeof import('vfile')>('vfile')
const file = new VFile({})
const file = new VFile({
value: text,
path: filename,
})
try {
await processor.process(file)
} catch (err) {
Expand Down
94 changes: 90 additions & 4 deletions packages/text/test/__snapshots__/fixtures.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fixtures: basic.md 1`] = `[]`;
exports[`fixtures: basic.md 1`] = `
[
{
"column": 7,
"endColumn": 10,
"endLine": 1,
"line": 1,
"message": "\`ani\` is misspelt; did you mean \`an\`, \`and\`, \`ans\`, \`ant\`, \`anti\`, \`any\`, \`bani\`, \`uni\`, \`Agni\`, \`AI\`, \`Ali\`, \`Ana\`, \`Ann\`, \`ANSI\`, \`API\`, \`AVI\`, \`MANI\`, \`Ni\`?
reference: -",
"nodeType": "Program",
"ruleId": "retext/ani",
"severity": 1,
},
{
"column": 4,
"endColumn": 18,
"endLine": 3,
"line": 3,
"message": "\`productentries\` is misspelt
reference: -",
"nodeType": "Program",
"ruleId": "retext/productentries",
"severity": 1,
},
{
"column": 4,
"endColumn": 22,
"endLine": 4,
"line": 4,
"message": "\`integrationclasses\` is misspelt
reference: -",
"nodeType": "Program",
"ruleId": "retext/integrationclasses",
"severity": 1,
},
]
`;

exports[`fixtures: basic.md 2`] = `undefined`;
exports[`fixtures: basic.md 2`] = `
"# I'm ani typo.
exports[`fixtures: basic.txt 1`] = `[]`;
## productentries
## integrationclasses
exports[`fixtures: basic.txt 2`] = `undefined`;
![GitHubb](githhub.com)
"
`;

exports[`fixtures: basic.txt 1`] = `
[
{
"column": 5,
"endColumn": 8,
"endLine": 1,
"line": 1,
"message": "\`ani\` is misspelt; did you mean \`an\`, \`and\`, \`ans\`, \`ant\`, \`anti\`, \`any\`, \`bani\`, \`uni\`, \`Agni\`, \`AI\`, \`Ali\`, \`Ana\`, \`Ann\`, \`ANSI\`, \`API\`, \`AVI\`, \`MANI\`, \`Ni\`?
reference: -",
"nodeType": "Program",
"ruleId": "retext/ani",
"severity": 1,
},
{
"column": 1,
"endColumn": 15,
"endLine": 3,
"line": 3,
"message": "\`productentries\` is misspelt; did you mean ?
reference: -",
"nodeType": "Program",
"ruleId": "retext/productentries",
"severity": 1,
},
{
"column": 1,
"endColumn": 19,
"endLine": 4,
"line": 4,
"message": "\`integrationclasses\` is misspelt; did you mean ?
reference: -",
"nodeType": "Program",
"ruleId": "retext/integrationclasses",
"severity": 1,
},
]
`;

exports[`fixtures: basic.txt 2`] = `
"I'm ani typo.
productentries
integrationclasses
"
`;
Loading

0 comments on commit 2a999ec

Please sign in to comment.