Skip to content

Commit

Permalink
fix: add concurrent limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Feb 11, 2018
1 parent 3dd9c8a commit aa4aa65
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 60 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This rule ignore errors on following nodes.

- CodeBlock
- Code
- Link
- Strong
- Emphasis
- BlockQuote
Expand All @@ -51,6 +52,11 @@ For example, Following text is ok
Find `...` in a string.
```

## Limitation

[proselint](https://github.com/amperser/proselint "proselint") can not run parallel.
This rule limit concurrency.

## Changelog

See [Releases page](https://github.com/textlint-rule/textlint-rule-proselint/releases).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"tabWidth": 4
},
"dependencies": {
"child-process-promise": "^2.2.1",
"execa": "^0.9.0",
"p-limit": "^1.2.0",
"textlint-rule-helper": "^2.0.0"
}
}
79 changes: 44 additions & 35 deletions src/textlint-rule-proselint.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// MIT © 2018 azu
"use strict";
const execa = require("execa");
const pLimit = require("p-limit");
const IgnoreNodeManager = require("textlint-rule-helper").IgnoreNodeManager;

const limit = pLimit(1);
const report = function(context) {
const { Syntax, RuleError, fixer, report } = context;
const filePath = context.getFilePath();
Expand All @@ -14,16 +17,18 @@ const report = function(context) {
ignoreNodeManager.ignoreChildrenByTypes(node, [
Syntax.CodeBlock,
Syntax.Code,
Syntax.Link,
Syntax.Strong,
Syntax.Emphasis,
Syntax.BlockQuote,
Syntax.Comment
]);
return execa("proselint", ["--json", filePath]).catch(error => {
if (error.code === "ENOENT") {
report(
node,
new RuleError(`Proselint not found.
return limit(() => {
return execa("proselint", ["--json", filePath]).catch(error => {
if (error.code === "ENOENT") {
return report(
node,
new RuleError(`Proselint not found.
Install proselint first:
Expand All @@ -33,41 +38,45 @@ More information:
https://github.com/textlint-rule/textlint-rule-proselint
`)
);
}
);
}

const json = JSON.parse(error.stdout);
if (json.status !== "success") {
return;
}
json.data.errors.forEach(lintError => {
const index = lintError.start - 1;
if (ignoreNodeManager.isIgnoredIndex(index)) {
if (error.code !== 1) {
return;
}
const json = JSON.parse(error.stdout);
if (json.status !== "success") {
return;
}
const canFixIt = typeof lintError.replacements === "string";
const source = lintError.source_url ? `Source: ${lintError.source_url}` : "";
const message = `[${lintError.check}] ${lintError.message}
json.data.errors.forEach(lintError => {
const index = lintError.start - 1;
if (ignoreNodeManager.isIgnoredIndex(index)) {
return;
}
const canFixIt = typeof lintError.replacements === "string";
const source = lintError.source_url ? `Source: ${lintError.source_url}` : "";
const message = `[${lintError.check}] ${lintError.message}
${source}
`.trim();
if (canFixIt) {
report(
node,
new RuleError(message, {
index: index,
severity: lintError.severity,
fix: fixer.replaceTextRange([index, lintError.end - 1], lintError.replacements)
})
);
} else {
report(
node,
new RuleError(message, {
index: index,
severity: lintError.severity
})
);
}
if (canFixIt) {
report(
node,
new RuleError(message, {
index: index,
severity: lintError.severity,
fix: fixer.replaceTextRange([index, lintError.end - 1], lintError.replacements)
})
);
} else {
report(
node,
new RuleError(message, {
index: index,
severity: lintError.severity
})
);
}
});
});
});
}
Expand Down
25 changes: 1 addition & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -867,14 +867,6 @@ charenc@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"

child-process-promise@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/child-process-promise/-/child-process-promise-2.2.1.tgz#4730a11ef610fad450b8f223c79d31d7bdad8074"
dependencies:
cross-spawn "^4.0.2"
node-version "^1.0.0"
promise-polyfill "^6.0.1"

chokidar@^1.6.1:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
Expand Down Expand Up @@ -996,13 +988,6 @@ cosmiconfig@^4.0.0:
parse-json "^4.0.0"
require-from-string "^2.0.1"

cross-spawn@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-4.0.2.tgz#7b9247621c23adfdd3856004a823cbe397424d41"
dependencies:
lru-cache "^4.0.1"
which "^1.2.9"

cross-spawn@^5.0.1:
version "5.1.0"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -2160,10 +2145,6 @@ node-pre-gyp@^0.6.39:
tar "^2.2.1"
tar-pack "^3.4.0"

node-version@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/node-version/-/node-version-1.1.0.tgz#f437d7ba407e65e2c4eaef8887b1718ba523d4f0"

noop-logger@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/noop-logger/-/noop-logger-0.1.1.tgz#94a2b1633c4f1317553007d8966fd0e841b6a4c2"
Expand Down Expand Up @@ -2312,7 +2293,7 @@ p-finally@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"

p-limit@^1.1.0:
p-limit@^1.1.0, p-limit@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.2.0.tgz#0e92b6bedcb59f022c13d0f1949dc82d15909f1c"
dependencies:
Expand Down Expand Up @@ -2488,10 +2469,6 @@ process-nextick-args@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.0.tgz#a37d732f4271b4ab1ad070d35508e8290788ffaa"

promise-polyfill@^6.0.1:
version "6.1.0"
resolved "https://registry.yarnpkg.com/promise-polyfill/-/promise-polyfill-6.1.0.tgz#dfa96943ea9c121fca4de9b5868cb39d3472e057"

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down

0 comments on commit aa4aa65

Please sign in to comment.