Skip to content

Commit

Permalink
feat(options): Add support extensions option (#9)
Browse files Browse the repository at this point in the history
* Support extensions option

* Update textlint

* Add test case

* Update README
  • Loading branch information
duck8823 authored and azu committed Aug 8, 2018
1 parent ab0fb5f commit ca5cb50
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ What is textlint plugin? Please see https://github.com/textlint/textlint/blob/ma

npm install textlint-plugin-html

## Supported extensions
## Default supported extensions

- `.html`
- `.htm`
Expand All @@ -32,6 +32,22 @@ Lint HTML file with textlint
$ textlint index.html
```

### Options
- `extensions`: `string[]`
- Additional file extensions for html

For example, if you want to treat `.custom-ext` as html, put following config to `.textlintrc`

```json
{
"plugins": {
"html": {
"extensions": [".custom-ext"]
}
}
}
```

## Tests

npm test
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"glob": "^7.1.1",
"mocha": "^3.2.0",
"power-assert": "^1.4.0",
"textlint": "^7.2.2",
"textlint": "^11.0.0",
"textlint-ast-test": "^1.1.3",
"textlint-rule-no-todo": "^2.0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions src/HTMLProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {parse} from "./html-to-ast";
export default class HTMLProcessor {
constructor(config) {
this.config = config;
this.extensions = this.config.extensions ? this.config.extensions : [];
}

static availableExtensions() {
availableExtensions() {
return [
".htm",
".html"
];
].concat(this.extensions);
}

processor(ext) {
Expand Down
34 changes: 29 additions & 5 deletions test/HTMLProcessor-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// LICENSE : MIT
"use strict";
import assert from "power-assert";
import HTMLProcessor from "../src/HTMLProcessor";
import HTMLPlugin from "../src/index"
import {parse} from "../src/html-to-ast";
import {tagNameToType} from "../src/mapping";
import {TextLintCore} from "textlint";
Expand Down Expand Up @@ -60,8 +60,8 @@ describe("HTMLProcessor-test", function () {
context("when target file is a HTML", function () {
beforeEach(function () {
textlint = new TextLintCore();
textlint.setupProcessors({
HTMLProcessor: HTMLProcessor
textlint.setupPlugins({
html: HTMLPlugin
});
textlint.setupRules({
"no-todo": require("textlint-rule-no-todo")
Expand All @@ -78,8 +78,8 @@ describe("HTMLProcessor-test", function () {
context("support file extensions", function () {
beforeEach(function () {
textlint = new TextLintCore();
textlint.setupProcessors({
HTMLProcessor: HTMLProcessor
textlint.setupPlugins({
html: HTMLPlugin
});
textlint.setupRules({
"no-todo": require("textlint-rule-no-todo")
Expand All @@ -99,5 +99,29 @@ describe("HTMLProcessor-test", function () {
return Promise.all(promises);
});
});
context("when extensions option is specified", function () {
beforeEach(function () {
textlint = new TextLintCore();
textlint.setupPlugins(
{ html: HTMLPlugin },
{ html: {extensions: [".custom"]}}
);
textlint.setupRules({
"no-todo": require("textlint-rule-no-todo")
});
});
it("should report error", function () {
const fixturePathList = [
path.join(__dirname, "/fixtures/test.custom")
];
const promises = fixturePathList.map((filePath) => {
return textlint.lintFile(filePath).then(results => {
assert(results.messages.length > 0);
assert(results.filePath === filePath);
});
});
return Promise.all(promises);
});
});
});
});
14 changes: 14 additions & 0 deletions test/fixtures/test.custom
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
<p>
TODO: This is TODO
</p>
</div>
</body>
</html>

0 comments on commit ca5cb50

Please sign in to comment.