GithubHelp home page GithubHelp logo

mkwtys / textlint Goto Github PK

View Code? Open in Web Editor NEW

This project forked from textlint/textlint

0.0 2.0 0.0 475 KB

The pluggable natural language linter for text and markdown.

Home Page: http://efcl.info/2015/09/10/introduce-textlint/

License: MIT License

JavaScript 99.68% Shell 0.32%

textlint's Introduction

textlint Build Status

The pluggable linting tool for text and markdown.

textlint is similar to ESLint.

Installation

$ npm install textlint -g

Usage

todo:lint result

  • more more document

textlint has not default rule!!

Use textlint with --rule or --ruledir, .textlintrc config file.

# Install textlint's rule
npm install --save-dev textlint-rule-no-todo

Use with textlint-rule-no-todo rule. (allow to short textlint-rule-no-todo to no-todo)

textlint --rule no-todo README.md

CLI

See command help.

$ textlint -h
  textlint [options] file.md [file.txt] [dir]
  
  Options:
    -h, --help                 Show help.
    -c, --config path::String  Use configuration from this file or sharable config.
    --plugin [String]          Specify plugins
    --rule [path::String]      Set rule package name
    --preset [path::String]    Set preset package name and load rules from preset package.
    --rulesdir [path::String]  Set rules from this directory and set all default rules to off.
    -f, --format String        Use a specific output format.
    -v, --version              Outputs the version number.
    --ext [String]             Specify text file extensions.
    --no-color                 Disable color in piped output.
    -o, --output-file path::String  Enable report to be written to a file.
    --quiet                    Report errors only. - default: false
    --stdin                    Lint code provided on <STDIN>. - default: false

Allow to use with multiple rules.

$ textlint --rule no-todo --rule very-nice-rule README.md

Example:

.textlintrc

.textlintrc is config file that is loaded as JSON, YAML or JS via MoOx/rc-loader.

$ textlint --rule no-todo --rule very-nice-rule README.md

is equal to create .textlintrc file

{
  "rules": {
    "no-todo": true,
    "very-nice-rule": true,
  }
}

and run textlint command

$ textlint README.md
# Automatically load `.textlintrc` in current directory

.textlintrc can define rule's option.

{
  "rules": {
    "no-todo": false, // disable
    "very-nice-rule": {
        "key": "value"
    }
  }
}

Pass rule's options("key": "value") to very-nice-rule.

It mean that use the following format:

{
  // Allow to comment in JSON
  "rules": {
    "<rule-name>": true | false | object
  }
}

ℹ️ for more details

Plugin

textlint plugin is a set of rules and rulesConfig or customize parser.

To enable plugin, put the "plugin-nameinto.textlinrc`.

// `.textlinrc`
{
    "plugins": [
        "plugin-name"
    ],
    // overwrite-plugins rules config
    // <plugin>/<rule>
    "rules": {
        "plugin-name/rule-name" : false
    }
}

ℹ️ See docs/plugin.md

Processor Plugin

Processor Plugin add new file format support. If you want to use textlint for HTML, use textlint-plugin-html as plugin.

npm install textlint-plugin-html

and Add "html" to .textlintrc

{
    "plugins": [
        "html"
    ]
}

Run textlint and work!

See Collection of textlint rule · textlint/textlint Wiki.

If you create new rule, and add it to the wiki :)

Built-in formatters

Currently, you can use "stylish" (defaults), "compact", "checkstyle", "jslint-xml", "junit", "tap", "pretty-error", "json".

e.g.) use pretty-error.js

$ textlint -f pretty-error file.md

More detail in textlint/textlint-formatter.

Use as node modules

You can use textlint as node modules.

$ npm install textlint --save-dev

Minimal usage:

import {TextLintEngine} from "textlint";
const engine = new TextLintEngine({
    rulePaths: ["path/to/rule-dir"]
});
engine.executeOnFiles(["README.md"]).then(results => {
    console.log(results[0].filePath);// => "README.md"
    // messages are `TextLintMessage` array.
    console.log(results[0].messages);
    /* 
    [
        {
            id: "rule-name",
            message:"lint message",
            line: 1, // 1-based columns(TextLintMessage)
            column:1 // 1-based columns(TextLintMessage)
        }
    ]
     */
    if (engine.isErrorResults(results)) {
        var output = engine.formatResults(results);
        console.log(output);
    }
});

Low level usage:

import {textlint} from "textlint";
textlint.setupRules({
    // rule-key : rule function(see docs/rule.md)
    "rule-key": function(context){
        var exports = {};
        exports[context.Syntax.Str] = function (node) {
            context.report(node, new context.RuleError("error message"));
        };
        return exports;
    }
});
textlint.lintMarkdown("# title").then(results => {
    console.log(results[0].filePath);// => "README.md"
    console.log(results[0].messages);// => [{message:"lint message"}]
});

More detail on:

Conclution

textlint has three extensible points

  • rule
    • rule is a rule for linting.
  • rule-preset
    • rule-preset contains rules.
  • plugin
    • plugin contains rules and a processor.

rule-preset-plugin

FAQ: How to create rules?

Please see docs/

Use with XXX

gulp plugin for textlint.

The plugin for Atom Linter provides an interface to textlint.

Who's using textlint?

The vuejs.org for japanese.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT and

lib/load-rules.js, util/traverse.js, cli.js and timing.js are:

ESLint
Copyright (c) 2013 Nicholas C. Zakas. All rights reserved.
https://github.com/eslint/eslint/blob/master/LICENSE

Related Work

SCG: TextLint is similar project.

SCG: TextLint's place is equal to my textlint(Fortuitously, project's name is the same too!).

concept

via Natural Language Checking with Program Checking Tools

Acknowledgements

Many thanks to ESLint.

textlint's People

Contributors

azu avatar kazupon avatar orangain avatar readmecritic avatar sindresorhus avatar koba04 avatar

Watchers

mkwtys avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.