Skip to content

Commit

Permalink
feat: Add support for all alex config options. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
robdodson authored Jul 31, 2020
1 parent 4eccb02 commit 5f82d00
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
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

0 comments on commit 5f82d00

Please sign in to comment.