get-alex / alex

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

How to use deny properly #292

Closed owlpaste closed 4 years ago

owlpaste commented 4 years ago

I am having issues getting the deny filter to work. Can I get an example where both allow and deny lists are used?

I was trying to use

.alexrc

{
  "allow": ["pop", "mom", "reject"],
  "deny": ["master"]
}

And the allow part gets applied fine, however deny does not. It wasn't really clear from examples as to how to use this?

wooorm commented 4 years ago

Sorry about that, I hadn’t released the recent deny feature yet. It’s now in alex@8.2.0!

Let me know if you have further questions.

owlpaste commented 4 years ago

Hiya, thanks for the quick reply, but still having issues @wooorm

➜ cat .alexrc
{
  "allow": ["pop", "mom", "reject"],
  "deny": ["master"]
}
➜ cat example.js
console.log(`bad example
it should fail
because he is silly
master
and sometimes
even a slave`);
➜ ./node_modules/.bin/alex example.js
example.js: no issues found
➜ ./node_modules/.bin/alex --version
8.2.0
owlpaste commented 4 years ago

Should I make a new issue/question @wooorm ?

wooorm commented 4 years ago

Sorry about the wait. The deny field is a recent addition, if it is configured, only deny is used, not allow. You should see an error if both are configured, so it’s a bug if you don’t see it (or you’re not on the latest alex? 🤔).

With deny, you create a list of rules to warn for. All the other rules don’t run. With allow, it’s the inverse: everything runs, except for the ones in allow!

owlpaste commented 4 years ago

Hiya, created https://github.com/owlpaste/alex-test as a quick test.

Was running this with

npm run lint-language *

> alex-test@0.0.1 lint-language /Users/user/projects/random/alex-test
> alex "example.js" "example.md" "node_modules" "package-lock.json" "package.json"

example.js: no issues found
example.md
  4:1-4:4  warning  `pop` may be insensitive, use `parent` instead  dad-mom  retext-equality

Fairly sure I am using it wrong, but a couple of things that are confusing me.

wooorm commented 4 years ago

Good catch! Welp, thanks to your repo I found out that deny isn’t supported on the CLI

wooorm commented 4 years ago

For your second point, “Ignoring js files even when passed in”, I don’t see that. It is checking a javascript file with alex example.js. But it’s interpreting it as markdown. Your backticks in example.js are seen in markdown as inline code, which alex ignored.

wooorm commented 4 years ago

Please see 9.0.1, which includes a fix for deny on the CLI!

owlpaste commented 4 years ago

For your second point, “Ignoring js files even when passed in”, I don’t see that. It is checking a javascript file with alex example.js. But it’s interpreting it as markdown. Your backticks in example.js are seen in markdown as inline code, which alex ignored.

Oh I see, thanks for the explanation, I didn't think of that.

Will test out the fix.

wooorm commented 4 years ago

If you don't want a file to be interpreted as md, mdx, html, or whatnot, I think there's a --text flag!

Good luck