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

Add support for all alex config options. #7

Merged
merged 1 commit into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ $ textlint --rule alex README.md

## Options

### `allow`
See [Alex's configuration documentation](https://github.com/get-alex/alex#configuration).

See Alex's document: [Ignoring messages](https://github.com/wooorm/alex#ignoring-messages "Ignoring messages")
### `allow`

```json
{
Expand All @@ -45,6 +45,42 @@ See Alex's document: [Ignoring messages](https://github.com/wooorm/alex#ignoring
}
```

### `deny`

```json
{
"rules": {
"alex": {
"deny": ["boogeyman-boogeywoman"]
}
}
}
```

### `noBinary`

```json
{
"rules": {
"alex": {
"noBinary": true
}
}
}
```

### `profanitySureness`

```json
{
"rules": {
"alex": {
"profanitySureness": 2
}
}
}
```

## Tests

npm test
Expand Down
10 changes: 7 additions & 3 deletions src/textlint-rule-alex.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import {RuleHelper} from "textlint-rule-helper";
import alex from "alex";
const defaultOptions = {
allow: []
allow: undefined,
deny: undefined,
noBinary: false,
profanitySureness: 0
};
module.exports = function textlintRuleAlex(context, options = {}) {
const {Syntax, RuleError, report, getSource} = context;
const helper = new RuleHelper(context);
const allowWords = options.allow || defaultOptions.allow;
const opts = {...defaultOptions, ...options};
console.log('opts', opts);
/*
{ [1:5-1:14: `boogeyman` may be insensitive, use `boogey` instead]
message: '`boogeyman` may be insensitive, use `boogey` instead',
Expand All @@ -35,7 +39,7 @@ module.exports = function textlintRuleAlex(context, options = {}) {
return;
}
const text = getSource(node);
const messages = alex(text, allowWords).messages;
const messages = alex(text, opts).messages;
messages.forEach((result) => {
reportError(node, result);
});
Expand Down