Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To be able to override the rules per file #709

Open
kazatsuyu opened this issue Oct 11, 2020 · 2 comments
Open

To be able to override the rules per file #709

kazatsuyu opened this issue Oct 11, 2020 · 2 comments
Labels
Status: Proposal Request for comments

Comments

@kazatsuyu
Copy link

I want to be able to set different rules for different paths, even within a single repository.
For example, zenn allows users to manage articles with GitHub integration, but we have to manage multiple articles and books in the same repository, and we may want to apply different rules to different articles and books.
To achieve this, I propose the following features.

per-directory .textlintrc

I want to put a .textlintrc file in a directory other than the root of the repository to override the root configuration.
I propose the following structure.

.textlintrc # (1)
a.md # The .textlintrc setting from (1) is used
b/.textlintrc # (2)
b/b.md # The setting of (1) overwritten by (2) will be used

Provide overrides that can override the rules at each path.

It would be nice to be able to write the following in .textlintrc.

{
    "rules": {
        "very-nice-rule": true
    },
    "overrides": [
        { "path": "a.md", "rules": { "very-nice-rule": false } },
        { "path": "b/*.md", "rules": { "very-nice-rule": { "key": "value" } } }
    ]
}

If overrides supports grub, there is no need for a per-directory .textlintrc, but I included it in the proposal because I thought it would be easier to manage.

The above has been translated by DeepL and the original text is as follows:

ファイルごとにルールを上書きできるようにする

一つのリポジトリ内であっても、異なるパスに対して別のルールを設定出来るようにしたい。

例えばzennではGitHub連携で記事を管理できますが、複数の記事と本を同一のリポジトリで管理することになり、異なる記事や本に対して異なるルールを適用したいことがあります。
これを実現するために、以下の機能を提案します。

ディレクトリ単位の.textlintrc

リポジトリのルート以外のディレクトリに置いた.textlintrcがルートの設定を上書きするようにしたい。
以下のような構造を提案します。

.textlintrc # (1)
a.md # (1)の.textlintrcの設定が利用される
b/.textlintrc # (2)
b/b.md # (1)の.textlintrcの設定を(2)の.textlintrcで上書きした設定が利用される

パスごとにルールを上書きできるoverridesを用意する

.textlintrcで以下のような書き方ができると良さそうです。

{
    "rules": {
        "very-nice-rule": true
    },
    "overrides": [
        { "path": "a.md", "rules": { "very-nice-rule": false } },
        { "path": "b/*.md", "rules": { "very-nice-rule": { "key": "value" } } }
    ]
}

overridesがgrubに対応していればディレクトリ単位の.textlintrcはなくても良いですが、あると管理がしやすいのではないかと思って提案に含めました。

@azu azu added the Status: Proposal Request for comments label Oct 11, 2020
@azu
Copy link
Member

azu commented Oct 11, 2020

The cascading mechanism(like per-directory) makes maintenance difficult.
The overrides feature is useful, but it may be complex.
Also, textlint does not support extends like ESLint and it may be files instead of overrides.

For example, ESLint will change its config format.

I wish that textlint config will be following:

  • Declarative(JSON first - migration-able)
  • Simple
  • Less config's option

I want to be able to set different rules for different paths, even within a single repository.

If you do lint in CLI, you can use --config flag.

textlint --config b/.textlintrc.json "b/**.md"

Another workaround: define your config in .textlintrc.js. Its just JavaScript, but it can not detect a linting file? maybe.


I think that the editor's linter may requires some override feature, because These editor resolve only specific file name like .textlintrc. So the editor's linter may not specify another textlintrc file name.

@MartinBonner
Copy link

I disagree that a cascading mechanism makes maintenance difficult. I find the mechanism used by .gitignore quite natural.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Proposal Request for comments
Projects
None yet
Development

No branches or pull requests

3 participants