Skip to content

Commit ca5cb50

Browse files
duck8823azu
authored andcommitted
feat(options): Add support extensions option (#9)
* Support extensions option * Update textlint * Add test case * Update README
1 parent ab0fb5f commit ca5cb50

File tree

5 files changed

+64
-9
lines changed

5 files changed

+64
-9
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ What is textlint plugin? Please see https://github.com/textlint/textlint/blob/ma
99

1010
npm install textlint-plugin-html
1111

12-
## Supported extensions
12+
## Default supported extensions
1313

1414
- `.html`
1515
- `.htm`
@@ -32,6 +32,22 @@ Lint HTML file with textlint
3232
$ textlint index.html
3333
```
3434

35+
### Options
36+
- `extensions`: `string[]`
37+
- Additional file extensions for html
38+
39+
For example, if you want to treat `.custom-ext` as html, put following config to `.textlintrc`
40+
41+
```json
42+
{
43+
"plugins": {
44+
"html": {
45+
"extensions": [".custom-ext"]
46+
}
47+
}
48+
}
49+
```
50+
3551
## Tests
3652

3753
npm test

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"glob": "^7.1.1",
4343
"mocha": "^3.2.0",
4444
"power-assert": "^1.4.0",
45-
"textlint": "^7.2.2",
45+
"textlint": "^11.0.0",
4646
"textlint-ast-test": "^1.1.3",
4747
"textlint-rule-no-todo": "^2.0.0"
4848
},

src/HTMLProcessor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import {parse} from "./html-to-ast";
44
export default class HTMLProcessor {
55
constructor(config) {
66
this.config = config;
7+
this.extensions = this.config.extensions ? this.config.extensions : [];
78
}
89

9-
static availableExtensions() {
10+
availableExtensions() {
1011
return [
1112
".htm",
1213
".html"
13-
];
14+
].concat(this.extensions);
1415
}
1516

1617
processor(ext) {

test/HTMLProcessor-test.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// LICENSE : MIT
22
"use strict";
33
import assert from "power-assert";
4-
import HTMLProcessor from "../src/HTMLProcessor";
4+
import HTMLPlugin from "../src/index"
55
import {parse} from "../src/html-to-ast";
66
import {tagNameToType} from "../src/mapping";
77
import {TextLintCore} from "textlint";
@@ -60,8 +60,8 @@ describe("HTMLProcessor-test", function () {
6060
context("when target file is a HTML", function () {
6161
beforeEach(function () {
6262
textlint = new TextLintCore();
63-
textlint.setupProcessors({
64-
HTMLProcessor: HTMLProcessor
63+
textlint.setupPlugins({
64+
html: HTMLPlugin
6565
});
6666
textlint.setupRules({
6767
"no-todo": require("textlint-rule-no-todo")
@@ -78,8 +78,8 @@ describe("HTMLProcessor-test", function () {
7878
context("support file extensions", function () {
7979
beforeEach(function () {
8080
textlint = new TextLintCore();
81-
textlint.setupProcessors({
82-
HTMLProcessor: HTMLProcessor
81+
textlint.setupPlugins({
82+
html: HTMLPlugin
8383
});
8484
textlint.setupRules({
8585
"no-todo": require("textlint-rule-no-todo")
@@ -99,5 +99,29 @@ describe("HTMLProcessor-test", function () {
9999
return Promise.all(promises);
100100
});
101101
});
102+
context("when extensions option is specified", function () {
103+
beforeEach(function () {
104+
textlint = new TextLintCore();
105+
textlint.setupPlugins(
106+
{ html: HTMLPlugin },
107+
{ html: {extensions: [".custom"]}}
108+
);
109+
textlint.setupRules({
110+
"no-todo": require("textlint-rule-no-todo")
111+
});
112+
});
113+
it("should report error", function () {
114+
const fixturePathList = [
115+
path.join(__dirname, "/fixtures/test.custom")
116+
];
117+
const promises = fixturePathList.map((filePath) => {
118+
return textlint.lintFile(filePath).then(results => {
119+
assert(results.messages.length > 0);
120+
assert(results.filePath === filePath);
121+
});
122+
});
123+
return Promise.all(promises);
124+
});
125+
});
102126
});
103127
});

test/fixtures/test.custom

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<div>
9+
<p>
10+
TODO: This is TODO
11+
</p>
12+
</div>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)