textlint

The pluggable natural language linter for text and markdown.

MIT License

Downloads
7.4M
Stars
2.8K
Committers
83

Bot releases are visible (Hide)

textlint - v13.1.0

Published by github-actions[bot] over 1 year ago

What's Changed

Features

$ npm install textlint textlint-plugin-html textlint-rule-preset-ja-technical-writing
$ npx textlint --init

will generate .textlintrc.json

{
  "plugins": {
    "html": true
  },
  "filters": {},
  "rules": {
    "preset-ja-technical-writing": true
  }
}

Testing

Dependency Updates

Full Changelog: https://github.com/textlint/textlint/compare/v13.0.5...13.1.0

textlint - v13.0.5

Published by github-actions[bot] over 1 year ago

What's Changed

Bug Fixes

This release correct ast-node-type types.

Full Changelog: https://github.com/textlint/textlint/compare/v13.0.4...13.0.5

textlint - v13.0.4

Published by github-actions[bot] over 1 year ago

What's Changed

Dependency Updates

It will reduce textlint package size.

image

https://bundlephobia.com/package/[email protected]
https://bundlephobia.com/package/[email protected]

172.8kb ⬇️

Full Changelog: https://github.com/textlint/textlint/compare/v13.0.3...13.0.4

textlint - v13.0.3

Published by github-actions[bot] over 1 year ago

What's Changed

Refactoring

It will reduce @textlint/kernel package size.

15.1kb ⬇️

Dependency Updates

Full Changelog: https://github.com/textlint/textlint/compare/v13.0.2...13.0.3

textlint - v13.0.2

Published by github-actions[bot] over 1 year ago

What's Changed

Bug Fixes

Full Changelog: https://github.com/textlint/textlint/compare/v13.0.1...13.0.2

textlint - v13.0.1

Published by github-actions[bot] over 1 year ago

What's Changed

Bug Fixes

If you have used TextNodeRange, TxtNodeLineLocation, TxtNodePosition, please change following:

- import type { TextNodeRange, TxtNodeLineLocation, TxtNodePosition } from "@textlint/ast-node-types";
+ import type { TxtNodeRange, TxtNodeLocation, TxtNodePosition } from "@textlint/ast-node-types";

Refactoring

Full Changelog: https://github.com/textlint/textlint/compare/v13.0.0...13.0.1

textlint - v13.0.0

Published by github-actions[bot] over 1 year ago

textlint v13 support ESM rules/plugins 🎉

We have rewritten CLI and textlint package.
However, it is not a breaking change for most textlint CLI users.
Almost CLI behaviors are the same as textlint v12.

Please share your feedback to us!

🔥 Breaking Changes

  • Require Node.js 16+
  • textlint --init output .textlintrc.json
    • Previously, textlint --init output .textlintrc
  • Improve @textlint/ast-node-types types
    • Now, All node types are defined!
    • It changes the existing node type and it is a breaking change
    • If you want to know TxtAST, please read TxtAST Interface
    • See also Release v13.0.1 · textlint/textlint
    • - import type { TextNodeRange, TxtNodeLineLocation, TxtNodePosition } from "@textlint/ast-node-types";
      + import type { TxtNodeRange, TxtNodeLocation, TxtNodePosition } from "@textlint/ast-node-types";
      
  • Use New-CLI instead of Old-CLI
    • textlint has introduced New-CLI and New-APIs in v12.3.0
    • New-CLI uses new APIs: createLinter/loadTextlintrc/loadLinterFormatter/loadFixerFormatter( If you want to know new APIs, please read Use as Node Modules)
    • It means that textlint support rules/plugins that are written by ESM 🎉
    • Remove Old-CLI

Difference between Old-CLI and New-CLI

  • New CLI support ESM rules/plugins
  • New CLI must require --stdin-filename with --stdin
    • --stdin-filename may be optional in Old-CLI
  • Correct exit status

Exit Status on new CLI

0: No Error

  • Not found lint error
  • --fix: found errors but fix all errors, so exit with 0
  • --output-file: Found lint error but --output-file is specified
  • --dryRun: Found lint error but --dryRun is specified

1: Lint Error

  • found lint error
  • --fix: found errors and could not fix all errors, so exit with 1

2: Fatal Error

  • Crash textlint process
  • Fail to load config/rule/plugin etc...

Remove undocumented way to override preset rule option

textlint v12 supported next textlintrc, but it is undocumented way.

{
  "rules": {
    "preset-ja-technical-writing": true,
    "ja-technical-writing/sentence-length": {
      "max": 100 // It override preset-ja-technical-writing's option
    }
  }
}

textlint v13 will remove this undocumented way.

You need to use next textlintrc.

{
  "rules": {
    "preset-ja-technical-writing": {
      "sentence-length": {
        "max": 100 // It override preset-ja-technical-writing's option
      }
    }
  }
}

For more details, see Configuring textlint · textlint

🆕 Features

Add individual Node type and Add Table/TableRow/TableCell node #1008

  • Define all node types in @textlint/ast-node-types
  • Add Table/TableRow/TableCell node to @textlint/ast-node-types

These types are defined in @textlint/ast-node-types.

Type name Node type Description
ASTNodeTypes.Document TxtDocumentNode(TxtParentNode) Root Node
ASTNodeTypes.DocumentExit TxtDocumentNode(TxtParentNode)
ASTNodeTypes.Paragraph TxtParagraphNode(TxtParentNode) Paragraph Node
ASTNodeTypes.ParagraphExit TxtParagraphNode(TxtParentNode)
ASTNodeTypes.BlockQuote TxtBlockQuoteNode(TxtParentNode) > Block Quote Node
ASTNodeTypes.BlockQuoteExit TxtBlockQuoteNode(TxtParentNode)
ASTNodeTypes.List TxtListNode(TxtParentNode) List Node
ASTNodeTypes.ListExit TxtListNode(TxtParentNode)
ASTNodeTypes.ListItem TxtListItemNode(TxtParentNode) List (each) item Node
ASTNodeTypes.ListItemExit TxtListItemNode(TxtParentNode)
ASTNodeTypes.Header TxtHeaderNode(TxtParentNode) # Header Node
ASTNodeTypes.HeaderExit TxtHeaderNode(TxtParentNode)
ASTNodeTypes.CodeBlock TxtCodeBlockNode(TxtParentNode) Code Block Node
ASTNodeTypes.CodeBlockExit TxtCodeBlockNode(TxtParentNode)
ASTNodeTypes.HtmlBlock TxtHtmlBlockNode(TxtParentNode) HTML Block Node
ASTNodeTypes.HtmlBlockExit TxtHtmlBlockNode(TxtParentNode)
ASTNodeTypes.Link TxtLinkNode(TxtParentNode) Link Node
ASTNodeTypes.LinkExit TxtLinkNode(TxtParentNode)
ASTNodeTypes.Delete TxtDeleteNode(TxtParentNode) Delete Node(~Str~)
ASTNodeTypes.DeleteExit TxtDeleteNode(TxtParentNode)
ASTNodeTypes.Emphasis TxtEmphasisNode(TxtParentNode) Emphasis(*Str*)
ASTNodeTypes.EmphasisExit TxtEmphasisNode(TxtParentNode)
ASTNodeTypes.Strong TxtStrongNode(TxtParentNode) Strong Node(**Str**)
ASTNodeTypes.StrongExit TxtStrongNode(TxtParentNode)
ASTNodeTypes.Break TxtBreakNode Hard Break Node(Str<space><space>)
ASTNodeTypes.BreakExit TxtBreakNode
ASTNodeTypes.Image TxtImageNode Image Node
ASTNodeTypes.ImageExit TxtImageNode
ASTNodeTypes.HorizontalRule TxtHorizontalRuleNode Horizontal Node(---)
ASTNodeTypes.HorizontalRuleExit TxtHorizontalRuleNode
ASTNodeTypes.Comment TxtCommentNode Comment Node
ASTNodeTypes.CommentExit TxtCommentNode
ASTNodeTypes.Str TxtStrNode Str Node
ASTNodeTypes.StrExit TxtStrNode
ASTNodeTypes.Code TxtCodeNode Inline Code Node
ASTNodeTypes.CodeExit TxtCodeNode
ASTNodeTypes.Html TxtHtmlNode Inline HTML Node
ASTNodeTypes.HtmlExit TxtHtmlNode
ASTNodeTypes.Table TxtTableNode Table node. textlint 13+
ASTNodeTypes.TableExit TxtTableNode
ASTNodeTypes.TableRow TxtTableRowNode Table row node. textlint 13+
ASTNodeTypes.TableRowExit TxtTableRowNode
ASTNodeTypes.TableCell TxtTableCellNode Table cell node. textlint 13+
ASTNodeTypes.TableCellExit TxtTableCellNode

Some nodes have additional properties.
For example, TxtHeaderNode has level property.

export interface TxtHeaderNode extends TxtParentNode {
    type: "Header";
    depth: 1 | 2 | 3 | 4 | 5 | 6;
    children: PhrasingContent[];
}

For more details, see @textlint/ast-node-types.

CHANGELOGS

Breaking Changes

Other Changes

Full Changelog: https://github.com/textlint/textlint/compare/v12.6.1...13.0.0

textlint - v12.6.1

Published by github-actions[bot] over 1 year ago

What's Changed

Refactoring

Dependency Updates

Full Changelog: https://github.com/textlint/textlint/compare/v12.6.0...12.6.1

textlint - v12.6.0

Published by github-actions[bot] over 1 year ago

What's Changed

Features

Bug Fixes

Refactoring

Dependency Updates

Full Changelog: https://github.com/textlint/textlint/compare/v12.5.1...12.6.0

textlint - v12.5.2

Published by github-actions[bot] over 1 year ago

What's Changed

Features

Bug Fixes

Refactoring

Dependency Updates

Full Changelog: https://github.com/textlint/textlint/compare/v12.5.1...12.5.2

textlint - v12.5.1

Published by azu almost 2 years ago

12.5.1 (2023-01-04)

Bug Fixes

Full Changelog: https://github.com/textlint/textlint/compare/v12.5.0...v12.5.1

textlint - v12.5.0

Published by azu almost 2 years ago

12.5.0 (2023-01-04)

Features

Example:

$ cat README.md | npx textlint --stdin --stdin-filename README.md --fix --format fixed-result --output-file NEW.md

For more details, see https://textlint.github.io/docs/cli.html#pipe-to-textlint

New Contributors

Full Changelog: https://github.com/textlint/textlint/compare/v12.4.0...v12.5.0

textlint - v12.4.0

Published by azu almost 2 years ago

12.4.0 (2023-01-02)

Features

  • textlint: add --print-config flag (9aa400f)

What's Changed

Full Changelog: https://github.com/textlint/textlint/compare/v12.3.1...v12.4.0

textlint - v12.3.1

Published by azu almost 2 years ago

12.3.1 (2022-12-30)

Bug Fixes

  • deps: update babel monorepo to ^7.20.7 (30a1386)
  • textlint: fix ESM loading issue on Windows (#972) (a6b9bf5)
textlint - v12.3.0

Published by azu almost 2 years ago

12.3.0 (2022-12-29)

Features

  • monorepo: upgrade to lerna@6 and use NX (#964) (e372795)
  • textlint: add new APIs and new CLI for ESM (#965) (3be8e39)

Overview

  • Support Rules/Filter/Pluugins that are written in ECMAScript Modules
  • Add new CLI
  • Add new APIs: createLinter/loadTextlintrc/loadLinterFormatter/loadFixerFormatter
    • It will replace TextLintCore/TextFixEngine/TextLintEngine

📝 ESM Rules/Filter/Pluugins only works in createLinter API.
This is because TextLintCore/TextFixEngine/TextLintEngine were assumed to be synchronous processes.
createLinter API does loading as async.

Breaking Changes

No changes in existing CLI.

Difference between Old-CLI and New-CLI

  • New CLI support ESM
  • New CLI must require --stdin-filename with --stdin
    • --stdin-filename may be optional in Old-CLI
  • Correct exit status

Exit Status on new CLI

0: No Error

  • Not found lint error
  • --fix: found errors but fix all errors, so exit with 0
  • --output-file: Found lint error but --output-file is specified
  • --dryRun: Found lint error but --dryRun is specified

1: Lint Error

  • found lint error
  • --fix: found errors and could not fix all errors, so exit with 1

2: Fatal Error

  • Crash textlint process
  • Fail to load config/rule/plugin etc...

New APIs

Ww introduce new API like createLinter for supporting Async APIs.
v13 continue to support current TextLintEngine and TextFixEngine for backward compatible.

  • #902

New createLinter and loadTextlintrc support ESM rules/plugins.
In other hands, TextLintEngine and TextFixEngine can not support ESM rules/plugins.

https://github.com/textlint/textlint/blob/60cea514f7eaefbff4411087d16a51daf68f12a4/packages/textlint/src/index.ts

API Description Behavior Target Platform Prev Status Next Status
cli Command LIne Interface Async Node.js ✅ (Use createTextlint internally)
textlint TextLintCore alias Async Node.js/CommonJS ❌ Deprecated ❌ Deprecated
TextLintCore Old API. It is Procedural API. Lint Only Single File. Recommended to use @texltint/kernel module instead of It. Async Node.js/CommonJS ❌ Deprecated ❌ Deprecated
TextLintEngine Lint Engine API. It load .textlintrc automaticaly ◉ Loading is Sync ◉ Linting is Async Node.js/CommonJS ✅ Recommended ❌ Deprecated
TextFixEngine Fix Engine API. It load .textlintrc automaticaly ◉ Loading is Sync ◉ Fixing is Async Node.js/CommonJS ✅ Recommended ❌ Deprecated
createLinter/loadTextlintrc Support Async APIs. ◉ Loading is Async◉ Linting/Fixing is Async Node.js/CommonJS and ESM None ✅ Recommended
  • createLinter: create linter instance
    • lintFiles(files): lint files and return linter messages
    • lintText(text, filePath) lint text with virtual filePath and return linter messages
    • fixFiles(files lint text and return fixer messages
    • fixText(text, filePath) lint text with virtual filePath and return fixer messages
      • fixFiles and fixText does not modify files
  • loadTextlintrc: load .textlintrc config file and return a descriptor object
  • loadLinerFormatter and loadFixerFormatter: load formatter

Lint files and output to console.

import { createLinter, loadTextlintrc, loadLinterFormatter } from "textlint";
// descriptor is a structure object for linter
// It includes rules, plugins, and options
const descriptor = await loadTextlintrc();
const linter = createLinter({
    descriptor
});
const results = await linter.lintFiles(["*.md"]);
// textlint has two types formatter sets for linter and fixer
const formatter = await loadLinterFormatter({ formatterName: "stylish" })
const output = formatter.format(results);
console.log(output);

For more details, see https://textlint.github.io/docs/use-as-modules.html

How to use New CLI

New CLI is opt-in for avoiding Breaking Changes.
It will be default in next major version.

You can try new textlint CLI via textlint-esm command.

- $ textlint "**/*.md"
+ $ textlint-esm "**/*.md"

Or, when TEXTLINT_USE_NEW_CLI=1 is set, textlint use new CLI

$ TEXTLINT_USE_NEW_CLI=1 textlint "**/*.md"

🔥 Welcome to feedback on Discussion: https://github.com/textlint/textlint/discussions/968

fix #868
fix https://github.com/textlint/textlint/issues/744 - new CLI fix this
fix https://github.com/textlint/textlint/issues/103 - new CLI fix this
fix #797 - extends descriptor instead of Config
fix #293 - TextlintCore will be removed in the future

textlint - v12.2.4

Published by azu almost 2 years ago

12.2.4 (2022-12-04)

Bug Fixes

  • deps: update babel monorepo to ^7.20.2 (4f0364a)
  • deps: update dependency @babel/cli to ^7.19.3 (c7124c6)
  • textlint: support linting dot files (#947) (8811922) by @kellyselden

This release allow to lint dot file when setting dot file name for extensions.

{
  plugins: {
    '@textlint/text': {
      extensions: ['.lint-todo'],
    },
  }
  rules: {
    'eol-last': true,
  }
};

This version can lint .lint-todo file.

npx textlint .lint-todo
textlint - v12.2.3

Published by azu almost 2 years ago

12.2.3 (2022-11-10)

Bug Fixes

  • deps: update babel monorepo to ^7.19.1 (6a0dbb8)
  • deps: update babel monorepo to ^7.19.3 (e5c80eb)
  • deps: update dependency @babel/core to ^7.19.6 (3ba99ea)
  • deps: update dependency @babel/preset-env to ^7.19.4 (d1049bd)
  • deps: update dependency table to ^6.8.1 (abcb864)
  • deps: update dependency traverse to ^0.6.7 (fc0ea91)
  • linter-formatter: added lodash to dependencies (#934) (e97efb8)
  • types: expose TextlintPluginPreProcessResult/TextlintPluginPostProcessResult type #920 (49d990a)
textlint - v12.2.2

Published by azu about 2 years ago

12.2.2 (2022-09-20)

Bug Fixes

  • markdown-to-ast: add mdast-util-gfm-autolink-literal to explicit deps (#904) (d2888a5)

This will fix pnpm issue #903

Dependencies Updates

  • deps: update babel monorepo to ^7.18.10 (dc0c555)
  • deps: update babel monorepo to ^7.18.6 (d8e30ae)
  • deps: update babel monorepo to ^7.18.6 (0f1b0fb)
  • deps: update babel monorepo to ^7.18.9 (558b4ee)
  • deps: update dependency @babel/core to ^7.18.13 (5c3ac1b)
  • deps: update dependency @babel/core to ^7.18.5 (17ab0d4)
textlint - v12.2.1

Published by azu over 2 years ago

12.2.1 (2022-06-25)

What's Changed

Full Changelog: https://github.com/textlint/textlint/compare/v12.1.0...v12.2.1

textlint - v12.2.0

Published by azu over 2 years ago

12.2.0 (2022-06-25)

Features

Implement Improve error location RFC #835
It will make the error location more details.

This change is for rule developer.

  • Add loc and range property to TextlintMessage(result)
  • Add padding prorperty to RuleError(message, details).
  • Add locator object to rule's context
    • lcoator.at(index), locator.range([startIndex, endIndex]), and locator.loc({ start: { line, column }, end: { line, column }}).
  • textlint-tester's valid and invalid support range property
  • Deprecate index, line and column property on TextlintMessage and report function
    • Preserve current behavior for backward compatible
  • Update filterMessages to use new range property on TextlintMessage
  • Use readonly [number, number] as range in all packages
  • Fix filterMessages bug https://github.com/textlint/textlint/pull/836/commits/c8a670f9b4fd7ce628a940dc4c8faabd5e62d396
  • Refactor tests
  • Update rule.md documentation
    • Add padding and locator object
    • Add peerDependencies note

textlint v12.2.0 will introduce padding and locator.
If your will use it, please add peerDependencies to package.json on your rule package.

  • Edit: No more peerDependencies. It is complex and there are less advantages.
  "peerDependencies": {
    "textlint": ">= 12.2.0"
  },
  "peerDependenciesMeta": {
    "textlint": {
      "optional": true
    }
  }

For textlint rule creator

Before:

const { Syntax, report, RuleError } = context;
// .....
report(node, new RuleError(message, {
  index: 1
}));

After:

const { Syntax, report, RuleError, locator } = context;
// .....
report(node, new RuleError(message, {
  padding: locator.at(1)
}));

If you want to get more correct location, please use locator.range or locator.loc

const { Syntax, report, RuleError, locator } = context;
// .....
report(node, new RuleError(message, {
  padding: locator.range([1, 5]) // The error related to 1 - 5 index.
}));

For more details, see https://textlint.github.io/docs/rule.html#ruleerror

  • #835

Changelogs

Bug Fixes

  • deps: update babel monorepo (89b2395)
  • deps: update babel monorepo (6a3e841)
  • deps: update babel monorepo (a91e594)
  • deps: update babel monorepo (c9f1957)
  • deps: update babel monorepo to ^7.16.5 (#834) (dcbc196)
  • deps: update babel monorepo to ^7.16.7 (e8c10aa)
  • deps: update babel monorepo to ^7.17.10 (1539f0a)
  • deps: Update chalk (#842) (56ba52c)
  • deps: update dependency @babel/core to ^7.17.12 (add5313)
  • deps: update dependency @babel/core to ^7.17.9 (db74d3a)
  • deps: update dependency @babel/core to ^7.18.2 (73c2047)
  • deps: update dependency table to ^6.7.5 (fdfcce6)
  • deps: update dependency table to ^6.8.0 (5e1aa18)
  • deps: Update packages that depend on ansi-regex (#841) (17c03cd)
  • deps: Update string-width (#844) (675bc93)
  • textlint: remove log-symbols (#845) (000d07a)

Features

  • textlint: add padding property and locator (#836) (f94d5f8)