Skip to content

Commit beb4d24

Browse files
committed
initial commit
0 parents  commit beb4d24

8 files changed

+282
-0
lines changed

.babelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["es2015"],
3+
"plugins": ["add-module-exports"]
4+
}

.gitignore

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# node-waf configuration
22+
.lock-wscript
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directory
28+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
29+
node_modules
30+
31+
# Debug log from npm
32+
npm-debug.log
33+
34+
35+
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore
36+
37+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
38+
39+
*.iml
40+
41+
## Directory-based project format:
42+
.idea/
43+
# if you remove the above rule, at least ignore the following:
44+
45+
# User-specific stuff:
46+
# .idea/workspace.xml
47+
# .idea/tasks.xml
48+
# .idea/dictionaries
49+
50+
# Sensitive or high-churn files:
51+
# .idea/dataSources.ids
52+
# .idea/dataSources.xml
53+
# .idea/sqlDataSources.xml
54+
# .idea/dynamic.xml
55+
# .idea/uiDesigner.xml
56+
57+
# Gradle:
58+
# .idea/gradle.xml
59+
# .idea/libraries
60+
61+
# Mongo Explorer plugin:
62+
# .idea/mongoSettings.xml
63+
64+
## File-based project format:
65+
*.ipr
66+
*.iws
67+
68+
## Plugin-specific files:
69+
70+
# IntelliJ
71+
out/
72+
73+
# mpeltonen/sbt-idea plugin
74+
.idea_modules/
75+
76+
# JIRA plugin
77+
atlassian-ide-plugin.xml
78+
79+
# Crashlytics plugin (for Android Studio and IntelliJ)
80+
com_crashlytics_export_strings.xml
81+
crashlytics.properties
82+
crashlytics-build.properties
83+
84+
85+
/lib

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 azu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# textlint-rule-alex
2+
3+
[textlint](https://github.com/textlint/textlint "textlint") rule for [ALEX](http://alexjs.com/ "ALEX").
4+
5+
> Whether your own or someone else’s writing, alex helps you find gender favouring, polarising, race related, religion inconsiderate, or other unequal phrasing.
6+
> -- [wooorm/alex: Catch insensitive, inconsiderate writing](https://github.com/wooorm/alex#alexvalue-allow "wooorm/alex: Catch insensitive, inconsiderate writing")
7+
8+
## Installation
9+
10+
npm install textlint-rule-alex
11+
12+
## Usage
13+
14+
Via `.textlintrc`(Recommended)
15+
16+
```json
17+
{
18+
"rules": {
19+
"alex": {
20+
"allow": []
21+
}
22+
}
23+
}
24+
```
25+
26+
Via CLI
27+
28+
## Options
29+
30+
### `allow`
31+
32+
See Alex's document: [Ignoring messages](https://github.com/wooorm/alex#ignoring-messages "Ignoring messages")
33+
34+
```json
35+
{
36+
"rules": {
37+
"alex": {
38+
"allow": ["boogeyman-boogeywoman"]
39+
}
40+
}
41+
}
42+
```
43+
44+
## Tests
45+
46+
npm test
47+
48+
## Contributing
49+
50+
1. Fork it!
51+
2. Create your feature branch: `git checkout -b my-new-feature`
52+
3. Commit your changes: `git commit -am 'Add some feature'`
53+
4. Push to the branch: `git push origin my-new-feature`
54+
5. Submit a pull request :D
55+
56+
## License
57+
58+
MIT

package.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "textlint-rule-alex",
3+
"repository": {
4+
"type": "git",
5+
"url": "git+https://github.com/azu/textlint-rule-alex.git"
6+
},
7+
"author": "azu",
8+
"email": "[email protected]",
9+
"homepage": "https://github.com/azu/textlint-rule-alex",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/azu/textlint-rule-alex/issues"
13+
},
14+
"version": "1.0.0",
15+
"description": "textlint rule for alex",
16+
"main": "lib/textlint-rule-alex.js",
17+
"files": [
18+
"lib",
19+
"src"
20+
],
21+
"directories": {
22+
"test": "test"
23+
},
24+
"scripts": {
25+
"build": "babel src --out-dir lib --source-maps",
26+
"watch": "babel src --out-dir lib --watch --source-maps",
27+
"prepublish": "npm run --if-present build",
28+
"test": "mocha"
29+
},
30+
"keywords": [
31+
"textlint",
32+
"alex"
33+
],
34+
"devDependencies": {
35+
"babel-cli": "^6.5.1",
36+
"babel-plugin-add-module-exports": "^0.1.2",
37+
"babel-preset-es2015": "^6.5.0",
38+
"babel-register": "^6.5.2",
39+
"mocha": "^2.4.5",
40+
"textlint-tester": "^0.4.1"
41+
},
42+
"dependencies": {
43+
"alex": "^2.0.1",
44+
"textlint-rule-helper": "^1.1.5"
45+
}
46+
}

src/textlint-rule-alex.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
import {RuleHelper} from "textlint-rule-helper";
4+
import alex from "alex";
5+
const defaultOptions = {
6+
allow: []
7+
};
8+
export default function textlintRuleAlex(context, options = {}) {
9+
const {Syntax, RuleError, report, getSource} = context;
10+
const helper = new RuleHelper(context);
11+
const allowWords = options.allow || defaultOptions.allow;
12+
/*
13+
{ [1:5-1:14: `boogeyman` may be insensitive, use `boogey` instead]
14+
message: '`boogeyman` may be insensitive, use `boogey` instead',
15+
name: '1:5-1:14',
16+
file: '',
17+
reason: '`boogeyman` may be insensitive, use `boogey` instead',
18+
line: 1,
19+
column: 5,
20+
location: Position { start: [Object], end: [Object] },
21+
fatal: false,
22+
ruleId: 'boogeyman-boogeywoman',
23+
source: 'retext-equality' }
24+
*/
25+
const reportError = (node, result) => {
26+
const ruleError = new RuleError(`[${result.ruleId}] ${result.message}`, {
27+
line: result.line - 1,
28+
column: result.column - 1
29+
});
30+
report(node, ruleError);
31+
};
32+
return {
33+
[Syntax.Str](node){
34+
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
35+
return;
36+
}
37+
const text = getSource(node);
38+
const messages = alex.text(text, allowWords).messages;
39+
messages.forEach((result) => {
40+
reportError(node, result);
41+
});
42+
}
43+
}
44+
}

test/mocha.opts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--compilers js:babel-register

test/textlint-rule-alex-test.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
var TextLintTester = require("textlint-tester");
4+
// rules
5+
var rule = require("../src/textlint-rule-alex");
6+
var tester = new TextLintTester();
7+
// ruleName, rule, expected[]
8+
tester.run("alex", rule, {
9+
valid: [
10+
"This is a pen",
11+
"男女"
12+
],
13+
invalid: [
14+
{
15+
text: "The boogeyman",
16+
errors: [
17+
{
18+
message: "[boogeyman-boogeywoman] `boogeyman` may be insensitive, use `boogey` instead",
19+
line: 1,
20+
column: 5
21+
}
22+
]
23+
}
24+
]
25+
});

0 commit comments

Comments
 (0)