textlint-rule-preset-jtf-style

repository·master·Indexed 42 days ago

https://github.com/textlint-ja/textlint-rule-preset-jtf-style

A textlint rule preset that implements the JTF Japanese Standard Style Guide (version 2.2) for translators working into Japanese. It provides automated checks for sentence style consistency (Desu-masu vs. Dearu), punctuation, character usage, and bulleted list consistency. Version 3.0.3 supports automatic fixing via the --fix flag and allows for granular configuration of rules, including dictionary-based rules, within the .textlintrc file.

Tokens
3K
Snippets
13
Records
17
Agent score
46%

What's inside textlint-rule-preset-jtf-style

  1. Configure textlint-rule-preset-jtf-style using .textlintrc

    master

    The recommended way to use the preset is to install it locally within your project. This keeps your environment clean.

    1. Initialize your project and install textlint and the preset as dev dependencies:
    npm init
    npm install -D textlint textlint-rule-preset-jtf-style
    1. Add the preset to your .textlintrc configuration file. Note that when using the preset name in the config, you must omit the textlint-rule- prefix and use preset-jtf-style.

    2. Run textlint against your target files. If running via node_modules/.bin/textlint, it will automatically pick up the .textlintrc in the current directory.

    {
        "rules": {
            "preset-jtf-style": true
        }
    }
  2. Use textlint-rule-preset-jtf-style via global installation

    master

    The quickest way to use the preset is to install textlint and the preset globally, then run textlint with the --preset flag. This will output the linting results for the specified file (e.g., README.md).

    npm install -g textlint textlint-rule-preset-jtf-style
    textlint --preset textlint-rule-preset-jtf-style README.md
  3. Automatically fix linting errors with --fix

    master

    Some rules within textlint-rule-preset-jtf-style support automatic fixing. You can use the --fix flag with the textlint command to automatically correct errors that can be determined mechanically.

    Warning: This command modifies your files directly. Always ensure you have a backup or use version control before running it.

    textlint --fix /path/to/target.md
  4. Migrate from `textlint-plugin-jtf-style` to `textlint-rule-preset-jtf-style`

    master

    If you are upgrading from the old plugin to the new preset, follow these steps:

    1. Swap the packages using npm:
    npm uninstall -D textlint-plugin-jtf-style
    npm install -D textlint-rule-preset-jtf-style
    1. Update your .textlintrc. Remove the jtf-style plugin entry and move the individual rules from the rules object (prefixed with jtf-style/) into the preset-jtf-style configuration object.
    // Old configuration (plugin-based)
    {
        "plugins": [
            "jtf-style"
        ],
        "rules": {
            "jtf-style/2.1.2.漢字": true,
            "jtf-style/2.1.5.カタカナ": true,
            "jtf-style/2.1.6.カタカナの長音": true,
            "jtf-style/2.2.1.ひらがなと漢字の使い分け": true
        }
    }
    
    // New configuration (preset-based)
    {
        "rules": {
            "preset-jtf-style": {
                "2.1.2.漢字": true,
                "2.1.5.カタカナ": true,
                "2.1.6.カタカナの長音": true,
                "2.2.1.ひらがなと漢字の使い分け": true
            }
        }
    }
  5. Enable dictionary-based rules

    master

    Several dictionary-based rules (which use regular expressions) are disabled by default because they can easily conflict with other textlint rules. If you wish to use them, you must explicitly enable them in your .textlintrc configuration.

    The following rules are disabled by default:

    • 2.1.2.漢字
    • 2.1.5.カタカナ
    • 2.1.6.カタカナの長音
    • 2.2.1.ひらがなと漢字の使い分け
    {
        "rules": {
            "preset-jtf-style": {
                "2.1.2.漢字": true,
                "2.1.5.カタカナ": true,
                "2.1.6.カタカナの長音": true,
                "2.2.1.ひらがなと漢字の使い分け": true
            }
        }
    }
  6. Disable specific rules in the preset

    master

    By default, all rules included in textlint-rule-preset-jtf-style are enabled. To disable a specific rule, set its key to false within the preset-jtf-style object in your .textlintrc configuration.

    Note that the rule keys follow the pattern jtf-style/<key_name>. You can find the exact key names in the src/index.js file of the package.

    {
        "rules": {
            "preset-jtf-style": {
                "1.2.2.ピリオド(.)とカンマ(,)": false
            }
        }
    }
  7. Enforce consistency in bulleted lists (Rule 1.1.3)

    master

    This rule ensures that bulleted lists (lists and list items) maintain stylistic consistency in two ways:

    1. Punctuation Consistency: All items in a single list must either all end with a period (。) or all not end with a period. If there is a mismatch, the rule enforces consistency based on which style is more frequent (or defaults to using periods if counts are equal).
    2. Politeness Level (Desu/Masu vs. Dearu) Consistency: All items in a single list must use the same politeness level. It checks for a mix of 敬体 (polite/desu-masu style) and 常体 (plain/dearu style). If a mix is detected, the rule enforces consistency, prioritizing 敬体 (desu-masu) if the counts are equal.

    Error Messages:

    • 箇条書きの文末に句点(。)を付けて下さい。: Add a period to the end of the list item.
    • 箇条書きの文末から句点(。)を外して下さい。: Remove the period from the end of the list item.
    • 箇条書きを敬体(ですます調)に統一して下さい。: Unify the list items to polite style (desu-masu).
    • 箇条書きを常体(である調)に統一して下さい。: Unify the list items to plain style (dearu).
  8. Configure spacing for half-width parentheses

    master

    The rule 3.3.かっこ類と隣接する文字の間のスペースの有無 (Spacing between parentheses and adjacent characters) allows you to control how half-width parentheses are handled via two options:

    1. allowOutsideHalfParentheses: Controls whether half-width spaces outside parentheses are allowed.

      • Default: true (allowed)
      • Set to false to prohibit spaces outside parentheses.
    2. requireOutsideHalfParentheses: Controls whether half-width spaces outside parentheses are required.

      • Default: false (not required)
      • Set to true to require spaces outside parentheses.
    {
      "rules": {
        "preset-jtf-style": {
          "3.3.かっこ類と隣接する文字の間のスペースの有無": {
            "allowOutsideHalfParentheses": false
          }
        }
      }
    }