Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Sep 12, 2015
0 parents commit f18b08c
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
### https://raw.github.com/github/gitignore/408c616ae0ad8f4b8101d8e876b9b67ac6b14059/Node.gitignore

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules


### https://raw.github.com/github/gitignore/408c616ae0ad8f4b8101d8e876b9b67ac6b14059/Global/JetBrains.gitignore

# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

*.iml

## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:

# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries

# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml

# Gradle:
# .idea/gradle.xml
# .idea/libraries

# Mongo Explorer plugin:
# .idea/mongoSettings.xml

## File-based project format:
*.ipr
*.iws

## Plugin-specific files:

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties


19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2015 azu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# textlint-rule-prh

[textlint](https://github.com/azu/textlint "textlint") rule for [vvakame/prh](https://github.com/vvakame/prh "vvakame/prh").

This rule check the spell by used with `rule.yaml`.

## Installation

npm install textlint-rule-prh

## Usage

1. It require Rule Options!

```json
{
"rules": {
"prh": {
"configPaths" :["path/to/rule.yaml"]
}
}
}
```

### What is rule.yaml?

Please See [vvakame/prh](https://github.com/vvakame/prh "vvakame/prh").

## Tests

npm test

## Contributing

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

## License

MIT
46 changes: 46 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "textlint-rule-prh",
"repository": {
"type": "git",
"url": "git+https://github.com/azu/textlint-rule-prh.git"
},
"author": "azu",
"email": "[email protected]",
"homepage": "https://github.com/azu/textlint-rule-prh",
"license": "MIT",
"bugs": {
"url": "https://github.com/azu/textlint-rule-prh/issues"
},
"version": "1.0.0",
"description": "textlint rule for prh.",
"main": "lib/prh-rule.js",
"files": [
"lib",
"src"
],
"directories": {
"test": "test"
},
"scripts": {
"build": "babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"prepublish": "npm run --if-present build",
"test": "mocha"
},
"keywords": [
"textlint",
"prh"
],
"dependencies": {
"prh": "^0.5.0",
"structured-source": "^3.0.2",
"textlint-rule-helper": "^1.1.3"
},
"devDependencies": {
"babel": "^5.8.23",
"espower-babel": "^3.3.0",
"mocha": "^2.3.2",
"power-assert": "^1.0.0",
"textlint": "^3.3.2"
}
}
46 changes: 46 additions & 0 deletions src/prh-rule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// LICENSE : MIT
"use strict";
import {RuleHelper} from "textlint-rule-helper";
import StructuredSource from "structured-source"
import prh from "prh";
export default function (context, options) {
if (typeof options === "undefined" || typeof options.configPaths === "undefined") {
throw new Error(`textlint-rule-prh require Rule Options.
Please set .textlinrc:
{
"rules": {
"prh": {
"configPaths" :["path/to/rule.yaml"]
}
}
}
`);
}
let helper = new RuleHelper(context);
let {Syntax, getSource, report, RuleError} = context;
var configPaths = options.configPaths;
var config = prh.fromYAMLFilePath(configPaths[0]);
configPaths.splice(1).forEach(function (path) {
var c = prh.fromYAMLFilePath(path);
config.merge(c);
});
return {
[Syntax.Str](node){
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
return;
}
let text = getSource(node);
// to get position from index
let src = new StructuredSource(text);
let makeChangeSet = config.makeChangeSet(null, text);
makeChangeSet.forEach(function (changeSet) {
var position = src.indexToPosition(changeSet.index);
// line, column
context.report(node, new context.RuleError(changeSet.matches[0] + " => " + changeSet.expected, {
line: position.line - 1,// == start with 0
column: position.column// == start with 0
}));
});
}
}
}
62 changes: 62 additions & 0 deletions test/fixtures/rule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: 1
rules:

# 大文字小文字全角半角の統一
- expected: Cookie
# 以下と等価 正規表現には強制でgフラグが付く
# - expected: Cookie
# pattern: "/[CcCc][OoOo][OoOo][KkKk][IiIi][EeEe]/g"
# options:
# wordBoundary: false
# specs: []

# 変換結果についてテストも書ける
- expected: jQuery
specs:
- from: jquery
to: jQuery
- from: JQUERY
to: jQuery

# 変換結果が期待通りではなかった場合、ルールのロードに失敗する
# - expected: JavaScript
# specs:
# - from: JAVASCRIPT
# to: JavaScprit # この場合はテスト側が間違ってる!
# Error: JavaScript spec failed. "JAVASCRIPT", expected "JavaScprit", but got "JavaScript", /[JjJj][AaAa][VvVv][AaAa][SsSs][CcCc][RrRr][IiIi][PpPp][TtTt]/g

# 表現の統一を図る
- expected: デフォルト
pattern: ディフォルト

# patternは複数記述可能
- expected: ハードウェア
pattern:
- ハードウエアー
- ハードウエア # 正規表現に変換する都合上短いものを後に書いたほうがよい
- ハードウェアー

# patternには正規表現が利用可能 否定戻り先読みが欲しい…(JSにはない
- expected: $1ソフトウェア
pattern: /([^経])ソフトウエア/
specs:
# 普通に変換
- from: 広義のソフトウエア
to: 広義のソフトウェア
# 日経ソフトウエア(書名)は変換しない
- from: 日経ソフトウエア
to: 日経ソフトウエア

# 単語境界の区別
- expected: js
# pattern: "/\b[JjJj][SsSs]\b/g" # と等価 \b が前後に付与される
options:
wordBoundary: true
specs:
- from: foo JS bar
to: foo js bar
- from: foo altJS bar
to: foo altJS bar
# 日本語+単語境界の仕様は自分で調べてね…!
- from: 今日もJS祭り
to: 今日もjs祭り
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--compilers js:espower-babel/guess
25 changes: 25 additions & 0 deletions test/prh-rule-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// LICENSE : MIT
"use strict";
import assert from "power-assert";
import {textlint} from "textlint";
import rule from "../src/prh-rule";
describe("prh-rule-test", function () {
beforeEach(function () {
textlint.setupRules({
"prh": rule
}, {
"prh": {
"configPaths": [__dirname + "/fixtures/rule.yaml"]
}
});
});
afterEach(function () {
textlint.resetRules();
});
it("should return json", function () {
var result = textlint.lintMarkdown("テストjquery");
assert(result.messages.length > 0);
assert(result.messages[0].line === 1);
assert(result.messages[0].column === 3);
});
});

0 comments on commit f18b08c

Please sign in to comment.