get-alex / alex

Catch insensitive, inconsiderate writing
https://alexjs.com
MIT License
4.81k stars 208 forks source link

The .alexrc.yml file should allow or deny words per selected file #340

Open tymonx opened 1 year ago

tymonx commented 1 year ago

Subject of the feature

The .alexrc.yml file should allow or deny words per selected file.

Problem

It is not possible to allow or deny some words per selected files. Sometimes is needed to allow some words in files but in other files not. For example license Apache 2.0 file contains executed and failure words.

Download Apache 2.0 file:

wget https://www.apache.org/licenses/LICENSE-2.0.txt

Run alex:

podman run -it --rm --volume "$(pwd):/alex:ro,z" --workdir "/alex" registry.gitlab.com/pipeline-components/alex:0.21.9 --why .

It returns status code 1 and prints:

LICENSE-2.0.txt
  136:34-136:42  warning  Be careful with `executed`, it’s profane in some cases  executed  retext-profanities
  161:54-161:61  warning  Be careful with `failure`, it’s profane in some cases   failure   retext-profanities

⚠ 2 warnings

Creating .alexignore file is not an option because of these issues:

Also it will entirely ignore content of whole file and this is also not desired.

Expected behaviour

Create .alexrc.yml with this content:

allow:
    - file: LICENSE
      words: [executed, failure]

    - file: fifo.cpp
      words: [pop]

It will be also nice if the file: entry will also support glob *.txt, **/*.cpp or regexp .*\.md$ patterns.

Still it should be possible to have backward compatibility with this YAML schema:

allow:
    - executed
    - failure
    - pop

Because it almost all YAML parser libraries it is possible to retrieve YAML type:

Alternatives

Create .alexrc.yml with this content:

allow:
    - executed
    - failure
    - pop

But this allow these words in all files.

Other alternative is using .alexignore file but this will ignore content of whole file and there is also still this issue: https://github.com/get-alex/alex/issues/170

wooorm commented 1 year ago

It is not possible to allow or deny some words per selected files.

You can allow/deny words from within files if you like, with comments: https://github.com/get-alex/alex#control.


Config files work the other way around:

  1. files are found on the file system (for example because you do alex some/folder/example.md.
  2. the closest config file is found, if there is one, so that could be some/folder/.alexrc or some/.alexrc or .alexrc or even higher.
  3. the contents of that config file could come from anywhere: it could be symlinked, it could be JS that imports some shared rules from node_modules etc

I don’t like the idea of having more globs or file paths inside config files to infinite recurse, and which would prevent sharing config files.


This issue is tracked at https://github.com/unifiedjs/unified-engine/issues/56.


But this allow these words in all files.

Each folder can have its own config file.


Other alternative is using .alexignore file but this will ignore content of whole file and there is also still this issue

I don‘t understand your problems with ignore files. I don’t see why there is an issue there?