Skip to content

support "max" options #1

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

Merged
merged 2 commits into from
Sep 8, 2015
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# textlint-rule-max-ten [![Build Status](https://travis-ci.org/azu/textlint-rule-max-ten.svg?branch=master)](https://travis-ci.org/azu/textlint-rule-max-ten)

[textlint](https://github.com/azu/textlint "textlint") rule is that limit maxinum ten(、) count of sentence.
[textlint](https://github.com/azu/textlint "textlint") rule is that limit maximum ten(、) count of sentence.

## Installation

Expand All @@ -12,6 +12,22 @@
$ textlint --rule max-ten README.md
# 11:0 error 一つの文で"、"を3つ以上使用しています max-ten

## Configure

Configure the maximum number of "、" allowed in a sentence. The default is `3`

Configure `"max"` value of the `.textlintrc` file.

```json
{
"rules": {
"max-ten": {
"max" : 3
}
}
}
```

## Tests

npm test
Expand Down
7 changes: 5 additions & 2 deletions src/max-ten.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// LICENSE : MIT
"use strict";
import {RuleHelper} from "textlint-rule-helper"

const defaultOptions = {max: 3};
function countTen(text) {
return text.split("、").length - 1;
}
/**
* @param {RuleContext} context
* @param {object} options
*/
export default function (context) {
var maxLen = 3;
export default function (context, options = defaultOptions) {
var maxLen = options.max;
const punctuation = /[。.]/;
let helper = new RuleHelper(context);
let {Syntax, RuleError, report, getSource} = context;
Expand Down
66 changes: 50 additions & 16 deletions test/max-ten-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,60 @@ import {textlint} from "textlint"
import rule from "../src/max-ten"
import path from "path"
import assert from "power-assert"
function textIncludeTen(count) {
return (new Array(count)).join("テスト、") + "です";
}
describe("max-ten", function () {
beforeEach(function () {
textlint.setupRules({
"max-ten": rule
});
});
afterEach(function () {
textlint.resetRules();
});
it("should report error", function () {
var filePath = path.join(__dirname, "/fixtures/error.md");
var result = textlint.lintFile(filePath);
assert(result.filePath === filePath);
assert(result.messages.length > 0);
assert.equal(result.messages[0].ruleId, "max-ten");
context("when use default option", function () {
beforeEach(function () {
textlint.setupRules({
"max-ten": rule
});
});
it("should report error", function () {
var filePath = path.join(__dirname, "/fixtures/error.md");
var result = textlint.lintFile(filePath);
assert(result.filePath === filePath);
assert(result.messages.length > 0);
assert.equal(result.messages[0].ruleId, "max-ten");
});
it("should not report error", function () {
var filePath = path.join(__dirname, "/fixtures/pass.md");
var result = textlint.lintFile(filePath);
assert(result.filePath === filePath);
assert(result.messages.length === 0);
});
});
it("should not report error", function () {
var filePath = path.join(__dirname, "/fixtures/pass.md");
var result = textlint.lintFile(filePath);
assert(result.filePath === filePath);
assert(result.messages.length === 0);
context("Change options#maxLen", function () {
context("when maxLen is 5, count of `、` < 5", function () {
it("should not report error", ()=> {
textlint.setupRules({
"max-ten": rule
}, {
"max-ten": {
"max": 5
}
});
var result = textlint.lintMarkdown("a、b、c、d、です。");
console.log(result.messages);
assert(result.messages.length === 0);
});
});
context("when maxLen is 5, count of `、` >= 5", function () {
it("should report error", ()=> {
textlint.setupRules({
"max-ten": rule
}, {
"max-ten": {
"max": 5
}
});
var result = textlint.lintMarkdown("a、b、c、d、e、です。");
assert(result.messages.length > 0);
});
});
});
});