prh 5.4.4 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/LICENSE +21 -0
- package/README.md +16 -1
- package/lib/changeset/changeset.js +33 -34
- package/lib/changeset/changeset.js.map +1 -1
- package/lib/changeset/diff.d.ts +2 -2
- package/lib/changeset/diff.js +37 -48
- package/lib/changeset/diff.js.map +1 -1
- package/lib/changeset/index.js +10 -9
- package/lib/changeset/index.js.map +1 -1
- package/lib/cli.js +58 -58
- package/lib/cli.js.map +1 -1
- package/lib/engine.js +42 -44
- package/lib/engine.js.map +1 -1
- package/lib/index.js +46 -58
- package/lib/index.js.map +1 -1
- package/lib/options.js +4 -4
- package/lib/options.js.map +1 -1
- package/lib/paragraph.js +16 -17
- package/lib/paragraph.js.map +1 -1
- package/lib/raw.js.map +1 -1
- package/lib/rule.js +61 -62
- package/lib/rule.js.map +1 -1
- package/lib/ruleSpec.js +7 -7
- package/lib/ruleSpec.js.map +1 -1
- package/lib/target.js +19 -19
- package/lib/target.js.map +1 -1
- package/lib/targetPattern.js +18 -18
- package/lib/targetPattern.js.map +1 -1
- package/lib/utils/content.js +6 -6
- package/lib/utils/content.js.map +1 -1
- package/lib/utils/regexp.js +50 -42
- package/lib/utils/regexp.js.map +1 -1
- package/package.json +24 -24
- package/prh-rules/media/WEB+DB_PRESS.yml +141 -21
- package/prh-rules/media/techbooster.yml +3 -1
- package/prh-rules/package-lock.json +52 -128
- package/prh-rules/package.json +4 -4
- package/prh-rules/test.js +13 -13
- package/tsconfig.json +6 -6
- package/.gitmodules +0 -3
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["cli.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["cli.ts"],"names":[],"mappings":";;AAAA,6BAA6B;AAC7B,yB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QAC3C,CAAC,CAAC,CAAC;IACP,CAAC;IAED,OAAO,IAAA,oBAAiB,EAAC,GAAG,SAAS,CAAC,CAAC;AAC3C,CAAC;AAED,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AAErD,SAAS,YAAY,CAAC,GAAQ;IAC1B,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;SAAM,CAAC;QACJ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;QACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import * as path from \"path\";\nimport * as fs from \"fs\";\nimport * as yaml from \"js-yaml\";\nimport * as diff from \"diff\";\n\nimport { fromYAMLFilePaths, getRuleFilePath } from \"./\";\nimport { indexToLineColumn } from \"./utils/content\";\n\nimport { Command } from \"commander\";\nconst pkg = require(\"../package.json\");\n\ninterface Options {\n rulesJson: boolean;\n rulesYaml: boolean;\n replace: boolean;\n verify: boolean;\n stdout: boolean;\n diff: boolean;\n verbose: boolean;\n rules?: string[];\n}\n\nconst program = new Command();\n\nprogram\n .name(\"prh\")\n .version(pkg.version, \"-v, --version\")\n .argument(\"[files...]\")\n .option(\"--rules-json\", \"emit rule set in json format\")\n .option(\"--rules-yaml\", \"emit rule set in yaml format\")\n .option(\"--rules <path>\", \"path to rule yaml file\", (value: string, previous: string[]) => previous.concat([value]), [] as string[])\n .option(\"--verify\", \"checking file validity\")\n .option(\"--stdout\", \"print replaced content to stdout\")\n .option(\"--diff\", \"show unified diff\")\n .option(\"--verbose\", \"makes output more verbose\")\n .option(\"-r, --replace\", \"replace input files\")\n .action((files: string[], opts: Options) => {\n if (opts.rulesJson || opts.rulesYaml) {\n if (opts.verbose) {\n console.warn(`processing ${process.cwd()} dir...`);\n }\n const engine = getEngineByTargetDir(process.cwd(), opts);\n if (opts.rulesJson) {\n console.log(JSON.stringify(engine, null, 2));\n return;\n } else if (opts.rulesYaml) {\n console.log(yaml.dump(JSON.parse(JSON.stringify(engine, null, 2))));\n return;\n }\n }\n\n if (files.length === 0) {\n throw new Error(\"files is required more than 1 argument\");\n }\n\n const invalidFiles: string[] = [];\n files.forEach((filePath) => {\n if (opts.verbose) {\n console.warn(`processing ${filePath}...`);\n }\n const content = fs.readFileSync(filePath, { encoding: \"utf8\" });\n const engine = getEngineByTargetDir(path.dirname(filePath), opts);\n const changeSet = engine.makeChangeSet(filePath);\n if (changeSet.diffs.length !== 0) {\n invalidFiles.push(filePath);\n }\n\n if (opts.stdout) {\n const result = changeSet.applyChangeSets(content);\n process.stdout.write(result);\n } else if (opts.diff) {\n const result = changeSet.applyChangeSets(content);\n const patch = diff.createPatch(filePath, content, result, \"before\", \"replaced\");\n console.log(patch);\n } else if (opts.replace) {\n const result = changeSet.applyChangeSets(content);\n if (content !== result) {\n fs.writeFileSync(filePath, result);\n console.warn(`replaced ${filePath}`);\n }\n } else {\n changeSet.diffs.forEach((d) => {\n const before = changeSet.content.substr(d.index, d.tailIndex - d.index);\n const after = d.newText;\n if (after == null) {\n return;\n }\n const lineColumn = indexToLineColumn(d.index, changeSet.content);\n console.log(`${changeSet.filePath}(${lineColumn.line + 1},${lineColumn.column + 1}): ${before} → ${after}`);\n });\n }\n });\n if (opts.verify && invalidFiles.length !== 0) {\n throw new Error(`${invalidFiles.join(\" ,\")} failed proofreading`);\n }\n });\n\nprogram\n .command(\"init\")\n .description(\"generate prh.yml\")\n .action(() => {\n fs.createReadStream(path.resolve(__dirname, \"../misc/prh.yml\")).pipe(fs.createWriteStream(\"prh.yml\"));\n console.log(\"create prh.yml\");\n console.log(\"see prh/rules collection https://github.com/prh/rules\");\n });\n\nfunction getEngineByTargetDir(targetDir: string, opts: Options) {\n let rulePaths: string[];\n if (opts.rules && opts.rules[0]) {\n rulePaths = [...opts.rules];\n } else {\n const foundPath = getRuleFilePath(targetDir);\n if (!foundPath) {\n throw new Error(`can't find rule file from ${targetDir}`);\n }\n\n rulePaths = [foundPath];\n }\n\n if (opts.verbose) {\n rulePaths.forEach((p, i) => {\n console.warn(` apply ${i + 1}: ${p}`);\n });\n }\n\n return fromYAMLFilePaths(...rulePaths);\n}\n\nprogram.parseAsync(process.argv).catch(errorHandler);\n\nfunction errorHandler(err: any) {\n if (err instanceof Error) {\n console.error(err.stack);\n } else {\n console.error(err);\n }\n return Promise.resolve(null).then(() => {\n process.exit(1);\n });\n}\n"]}
|
package/lib/engine.js
CHANGED
|
@@ -1,56 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
exports.Engine = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const regexp_1 = require("./utils/regexp");
|
|
6
|
+
const paragraph_1 = require("./paragraph");
|
|
7
|
+
const target_1 = require("./target");
|
|
8
|
+
const rule_1 = require("./rule");
|
|
9
|
+
const changeset_1 = require("./changeset");
|
|
10
|
+
class Engine {
|
|
11
|
+
constructor(src) {
|
|
11
12
|
if (!src) {
|
|
12
|
-
throw new Error("src is
|
|
13
|
+
throw new Error("src is required");
|
|
13
14
|
}
|
|
14
15
|
this.version = +src.version || 1;
|
|
15
|
-
this.targets = (src.targets || []).map(
|
|
16
|
-
this.rules = (src.rules || []).map(
|
|
16
|
+
this.targets = (src.targets || []).map((target) => new target_1.Target(target));
|
|
17
|
+
this.rules = (src.rules || []).map((rule) => new rule_1.Rule(rule));
|
|
17
18
|
this.sourcePaths = [];
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
var _this = this;
|
|
20
|
+
merge(other) {
|
|
21
21
|
if (!other) {
|
|
22
22
|
throw new Error("other is required");
|
|
23
23
|
}
|
|
24
24
|
if (this.version !== other.version) {
|
|
25
25
|
throw new Error("version mismatch!");
|
|
26
26
|
}
|
|
27
|
-
other.sourcePaths.forEach(
|
|
28
|
-
|
|
27
|
+
other.sourcePaths.forEach((sourcePath) => {
|
|
28
|
+
const exists = this.sourcePaths.filter((otherSourcePath) => otherSourcePath === sourcePath).length !== 0;
|
|
29
29
|
if (!exists) {
|
|
30
|
-
|
|
30
|
+
this.sourcePaths.push(sourcePath);
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
-
other.targets.forEach(
|
|
34
|
-
|
|
33
|
+
other.targets.forEach((otherTarget) => {
|
|
34
|
+
const exists = this.targets.filter((target) => (0, regexp_1.equals)(target.file, otherTarget.file)).length !== 0;
|
|
35
35
|
if (!exists) {
|
|
36
|
-
|
|
36
|
+
this.targets.push(otherTarget);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
// NOTE https://github.com/vvakame/prh/issues/18#issuecomment-222524140
|
|
40
|
-
|
|
41
|
-
return
|
|
40
|
+
const reqRules = other.rules.filter((otherRule) => {
|
|
41
|
+
return this.rules.filter((rule) => rule.expected === otherRule.expected).length === 0;
|
|
42
42
|
});
|
|
43
43
|
this.rules = this.rules.concat(reqRules);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var paragraphs = [];
|
|
44
|
+
}
|
|
45
|
+
makeChangeSet(filePath, contentText) {
|
|
46
|
+
const content = contentText != null ? contentText : fs.readFileSync(filePath, { encoding: "utf8" });
|
|
47
|
+
const re = /([^]*?)\n{2,}/g;
|
|
48
|
+
const paragraphs = [];
|
|
50
49
|
{
|
|
51
|
-
|
|
50
|
+
let lastIndex = 0;
|
|
52
51
|
while (true) {
|
|
53
|
-
|
|
52
|
+
const matches = re.exec(content);
|
|
54
53
|
if (!matches) {
|
|
55
54
|
paragraphs.push(new paragraph_1.Paragraph(lastIndex, content.substr(lastIndex)));
|
|
56
55
|
break;
|
|
@@ -59,19 +58,19 @@ var Engine = /** @class */ (function () {
|
|
|
59
58
|
lastIndex = re.lastIndex;
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this.targets.forEach(
|
|
61
|
+
const diffs = paragraphs.map((p) => p.makeDiffs(this.rules)).reduce((p, c) => p.concat(c), []);
|
|
62
|
+
let changeSet = new changeset_1.ChangeSet({ filePath, content, diffs });
|
|
63
|
+
let includes = null;
|
|
64
|
+
let excludes = null;
|
|
65
|
+
this.targets.forEach((target) => {
|
|
67
66
|
target.reset();
|
|
68
67
|
if (!target.file.test(filePath)) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
70
|
if (target.includes.length !== 0) {
|
|
72
71
|
// .ts の // の後や /* */ の内部だけ対象にしたい場合のための機能
|
|
73
|
-
target.includes.forEach(
|
|
74
|
-
|
|
72
|
+
target.includes.forEach((include) => {
|
|
73
|
+
const intersect = (0, changeset_1.makeChangeSet)(filePath, content, include.pattern);
|
|
75
74
|
if (includes) {
|
|
76
75
|
includes = includes.concat(intersect);
|
|
77
76
|
}
|
|
@@ -82,8 +81,8 @@ var Engine = /** @class */ (function () {
|
|
|
82
81
|
}
|
|
83
82
|
if (target.excludes.length !== 0) {
|
|
84
83
|
// .re の #@ の後を対象にしたくない場合のための機能
|
|
85
|
-
target.excludes.forEach(
|
|
86
|
-
|
|
84
|
+
target.excludes.forEach((exclude) => {
|
|
85
|
+
const subsract = (0, changeset_1.makeChangeSet)(filePath, content, exclude.pattern);
|
|
87
86
|
if (excludes) {
|
|
88
87
|
excludes = excludes.concat(subsract);
|
|
89
88
|
}
|
|
@@ -100,15 +99,14 @@ var Engine = /** @class */ (function () {
|
|
|
100
99
|
changeSet = changeSet.subtract(excludes);
|
|
101
100
|
}
|
|
102
101
|
return changeSet;
|
|
103
|
-
}
|
|
104
|
-
|
|
102
|
+
}
|
|
103
|
+
replaceByRule(filePath, content) {
|
|
105
104
|
if (content == null) {
|
|
106
105
|
content = fs.readFileSync(filePath, { encoding: "utf8" });
|
|
107
106
|
}
|
|
108
|
-
|
|
107
|
+
const changeSet = this.makeChangeSet(filePath, content);
|
|
109
108
|
return changeSet.applyChangeSets(content);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
}());
|
|
109
|
+
}
|
|
110
|
+
}
|
|
113
111
|
exports.Engine = Engine;
|
|
114
112
|
//# sourceMappingURL=engine.js.map
|
package/lib/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["engine.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AAEzB,2CAAwC;AAGxC,2CAAwC;AACxC,qCAAkC;AAClC,iCAA8B;AAC9B,2CAAuD;AAEvD,MAAa,MAAM;IAMf,YAAY,GAAe;QACvB,IAAI,CAAC,GAAG,EAAE,CAAC;YACP,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACvC,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACvE,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,WAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7D,IAAI,CAAC,WAAW,GAAG,EAAE,CA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C;YACP,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,IAAI,QAAQ,EAAE,CAAC;YACX,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,QAAQ,EAAE,CAAC;YACX,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,aAAa,CAAC,QAAgB,EAAE,OAAgB;QAC5C,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACxD,OAAO,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACJ;AA/GD,wBA+GC","sourcesContent":["import * as fs from \"fs\";\n\nimport { equals } from \"./utils/regexp\";\n\nimport * as raw from \"./raw\";\nimport { Paragraph } from \"./paragraph\";\nimport { Target } from \"./target\";\nimport { Rule } from \"./rule\";\nimport { makeChangeSet, ChangeSet } from \"./changeset\";\n\nexport class Engine {\n version: number;\n targets: Target[];\n rules: Rule[];\n sourcePaths: string[]; // NOTE ソースとなったファイルのパス\n\n constructor(src: raw.Config) {\n if (!src) {\n throw new Error(\"src is required\");\n }\n this.version = +src.version || 1;\n this.targets = (src.targets || []).map((target) => new Target(target));\n this.rules = (src.rules || []).map((rule) => new Rule(rule));\n this.sourcePaths = [];\n }\n\n merge(other: Engine) {\n if (!other) {\n throw new Error(\"other is required\");\n }\n if (this.version !== other.version) {\n throw new Error(\"version mismatch!\");\n }\n other.sourcePaths.forEach((sourcePath) => {\n const exists = this.sourcePaths.filter((otherSourcePath) => otherSourcePath === sourcePath).length !== 0;\n if (!exists) {\n this.sourcePaths.push(sourcePath);\n }\n });\n other.targets.forEach((otherTarget) => {\n const exists = this.targets.filter((target) => equals(target.file, otherTarget.file)).length !== 0;\n if (!exists) {\n this.targets.push(otherTarget);\n }\n });\n // NOTE https://github.com/vvakame/prh/issues/18#issuecomment-222524140\n const reqRules = other.rules.filter((otherRule) => {\n return this.rules.filter((rule) => rule.expected === otherRule.expected).length === 0;\n });\n this.rules = this.rules.concat(reqRules);\n }\n\n makeChangeSet(filePath: string, contentText?: string): ChangeSet {\n const content: string = contentText != null ? contentText : fs.readFileSync(filePath, { encoding: \"utf8\" });\n\n const re = /([^]*?)\\n{2,}/g;\n const paragraphs: Paragraph[] = [];\n {\n let lastIndex = 0;\n while (true) {\n const matches = re.exec(content);\n if (!matches) {\n paragraphs.push(new Paragraph(lastIndex, content.substr(lastIndex)));\n break;\n }\n paragraphs.push(new Paragraph(matches.index, matches[1]));\n lastIndex = re.lastIndex;\n }\n }\n\n const diffs = paragraphs.map((p) => p.makeDiffs(this.rules)).reduce((p, c) => p.concat(c), []);\n let changeSet = new ChangeSet({ filePath, content, diffs });\n\n let includes: ChangeSet | null = null;\n let excludes: ChangeSet | null = null;\n this.targets.forEach((target) => {\n target.reset();\n if (!target.file.test(filePath)) {\n return;\n }\n if (target.includes.length !== 0) {\n // .ts の // の後や /* */ の内部だけ対象にしたい場合のための機能\n target.includes.forEach((include) => {\n const intersect = makeChangeSet(filePath, content, include.pattern);\n if (includes) {\n includes = includes.concat(intersect);\n } else {\n includes = intersect;\n }\n });\n }\n if (target.excludes.length !== 0) {\n // .re の #@ の後を対象にしたくない場合のための機能\n target.excludes.forEach((exclude) => {\n const subsract = makeChangeSet(filePath, content, exclude.pattern);\n if (excludes) {\n excludes = excludes.concat(subsract);\n } else {\n excludes = subsract;\n }\n });\n }\n });\n\n if (includes) {\n changeSet = changeSet.intersect(includes);\n }\n if (excludes) {\n changeSet = changeSet.subtract(excludes);\n }\n\n return changeSet;\n }\n\n replaceByRule(filePath: string, content?: string) {\n if (content == null) {\n content = fs.readFileSync(filePath, { encoding: \"utf8\" });\n }\n const changeSet = this.makeChangeSet(filePath, content);\n return changeSet.applyChangeSets(content);\n }\n}\n"]}
|
package/lib/index.js
CHANGED
|
@@ -1,54 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.
|
|
8
|
-
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
exports.Diff = exports.ChangeSet = exports.Engine = void 0;
|
|
4
|
+
exports.fromYAMLFilePaths = fromYAMLFilePaths;
|
|
5
|
+
exports.fromYAMLFilePath = fromYAMLFilePath;
|
|
6
|
+
exports.fromYAML = fromYAML;
|
|
7
|
+
exports.fromRowConfig = fromRowConfig;
|
|
8
|
+
exports.fromYAMLFilePathsAsync = fromYAMLFilePathsAsync;
|
|
9
|
+
exports.fromYAMLFilePathAsync = fromYAMLFilePathAsync;
|
|
10
|
+
exports.fromYAMLAsync = fromYAMLAsync;
|
|
11
|
+
exports.fromRowConfigAsync = fromRowConfigAsync;
|
|
12
|
+
exports.getRuleFilePath = getRuleFilePath;
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const path = require("path");
|
|
15
|
+
const yaml = require("js-yaml");
|
|
16
|
+
const engine_1 = require("./engine");
|
|
17
|
+
Object.defineProperty(exports, "Engine", { enumerable: true, get: function () { return engine_1.Engine; } });
|
|
18
|
+
const changeset_1 = require("./changeset/");
|
|
19
|
+
Object.defineProperty(exports, "ChangeSet", { enumerable: true, get: function () { return changeset_1.ChangeSet; } });
|
|
20
|
+
Object.defineProperty(exports, "Diff", { enumerable: true, get: function () { return changeset_1.Diff; } });
|
|
21
|
+
function fromYAMLFilePaths(...configPaths) {
|
|
22
|
+
const engine = fromYAMLFilePath(configPaths[0]);
|
|
23
|
+
configPaths.splice(1).forEach((path) => {
|
|
18
24
|
engine.merge(fromYAMLFilePath(path));
|
|
19
25
|
});
|
|
20
26
|
return engine;
|
|
21
27
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (opts === void 0) { opts = {}; }
|
|
25
|
-
var content = fs.readFileSync(configPath, { encoding: "utf8" });
|
|
28
|
+
function fromYAMLFilePath(configPath, opts = {}) {
|
|
29
|
+
const content = fs.readFileSync(configPath, { encoding: "utf8" });
|
|
26
30
|
return fromYAML(configPath, content, opts);
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (opts === void 0) { opts = {}; }
|
|
31
|
-
var rawConfig = yaml.load(yamlContent);
|
|
32
|
+
function fromYAML(configPath, yamlContent, opts = {}) {
|
|
33
|
+
const rawConfig = yaml.load(yamlContent);
|
|
32
34
|
return fromRowConfig(configPath, rawConfig, opts);
|
|
33
35
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (opts === void 0) { opts = {}; }
|
|
37
|
-
var engine = new engine_1.Engine(rawConfig);
|
|
36
|
+
function fromRowConfig(configPath, rawConfig, opts = {}) {
|
|
37
|
+
const engine = new engine_1.Engine(rawConfig);
|
|
38
38
|
engine.sourcePaths.push(path.normalize(configPath));
|
|
39
39
|
if (!opts.disableImports && rawConfig.imports) {
|
|
40
40
|
// TODO この辺の処理をEngine側に移したい
|
|
41
41
|
// なるべく破壊的変更を避ける
|
|
42
42
|
// fsやyamlを使わずに同等のEngineを組み立てる余地を残す
|
|
43
43
|
// async化したいけどprhの参照パッケージが壊れるのが辛い
|
|
44
|
-
|
|
44
|
+
let importSpecs;
|
|
45
45
|
if (typeof rawConfig.imports === "string") {
|
|
46
|
-
importSpecs = [
|
|
46
|
+
importSpecs = [
|
|
47
|
+
{
|
|
47
48
|
path: rawConfig.imports,
|
|
48
|
-
}
|
|
49
|
+
},
|
|
50
|
+
];
|
|
49
51
|
}
|
|
50
52
|
else {
|
|
51
|
-
importSpecs = rawConfig.imports.map(
|
|
53
|
+
importSpecs = rawConfig.imports.map((imp) => {
|
|
52
54
|
if (typeof imp === "string") {
|
|
53
55
|
return {
|
|
54
56
|
path: imp,
|
|
@@ -57,16 +59,16 @@ function fromRowConfig(configPath, rawConfig, opts) {
|
|
|
57
59
|
return imp;
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
|
-
importSpecs.forEach(
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
importSpecs.forEach((importSpec) => {
|
|
63
|
+
const importedConfigPath = path.join(path.dirname(configPath), importSpec.path);
|
|
64
|
+
const newEngine = fromYAMLFilePath(importedConfigPath, {
|
|
63
65
|
disableImports: !!importSpec.disableImports,
|
|
64
66
|
});
|
|
65
|
-
|
|
67
|
+
const ignoreRules = (importSpec.ignoreRules || []).map((ignoreRule) => {
|
|
66
68
|
return typeof ignoreRule === "string" ? { pattern: ignoreRule } : ignoreRule;
|
|
67
69
|
});
|
|
68
|
-
newEngine.rules = newEngine.rules.filter(
|
|
69
|
-
return ignoreRules.every(
|
|
70
|
+
newEngine.rules = newEngine.rules.filter((rule) => {
|
|
71
|
+
return ignoreRules.every((ignoreRule) => {
|
|
70
72
|
return !rule._shouldIgnore(ignoreRule);
|
|
71
73
|
});
|
|
72
74
|
});
|
|
@@ -75,22 +77,15 @@ function fromRowConfig(configPath, rawConfig, opts) {
|
|
|
75
77
|
}
|
|
76
78
|
return engine;
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
function fromYAMLFilePathsAsync() {
|
|
80
|
-
var configPaths = [];
|
|
81
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
82
|
-
configPaths[_i] = arguments[_i];
|
|
83
|
-
}
|
|
80
|
+
function fromYAMLFilePathsAsync(...configPaths) {
|
|
84
81
|
try {
|
|
85
|
-
return Promise.resolve(fromYAMLFilePaths
|
|
82
|
+
return Promise.resolve(fromYAMLFilePaths(...configPaths));
|
|
86
83
|
}
|
|
87
84
|
catch (e) {
|
|
88
85
|
return Promise.reject(e);
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
|
-
|
|
92
|
-
function fromYAMLFilePathAsync(configPath, opts) {
|
|
93
|
-
if (opts === void 0) { opts = {}; }
|
|
88
|
+
function fromYAMLFilePathAsync(configPath, opts = {}) {
|
|
94
89
|
try {
|
|
95
90
|
return Promise.resolve(fromYAMLFilePath(configPath, opts));
|
|
96
91
|
}
|
|
@@ -98,9 +93,7 @@ function fromYAMLFilePathAsync(configPath, opts) {
|
|
|
98
93
|
return Promise.reject(e);
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
|
-
|
|
102
|
-
function fromYAMLAsync(configPath, yamlContent, opts) {
|
|
103
|
-
if (opts === void 0) { opts = {}; }
|
|
96
|
+
function fromYAMLAsync(configPath, yamlContent, opts = {}) {
|
|
104
97
|
try {
|
|
105
98
|
return Promise.resolve(fromYAML(configPath, yamlContent, opts));
|
|
106
99
|
}
|
|
@@ -108,9 +101,7 @@ function fromYAMLAsync(configPath, yamlContent, opts) {
|
|
|
108
101
|
return Promise.reject(e);
|
|
109
102
|
}
|
|
110
103
|
}
|
|
111
|
-
|
|
112
|
-
function fromRowConfigAsync(configPath, rawConfig, opts) {
|
|
113
|
-
if (opts === void 0) { opts = {}; }
|
|
104
|
+
function fromRowConfigAsync(configPath, rawConfig, opts = {}) {
|
|
114
105
|
try {
|
|
115
106
|
return Promise.resolve(fromRowConfig(configPath, rawConfig, opts));
|
|
116
107
|
}
|
|
@@ -118,10 +109,8 @@ function fromRowConfigAsync(configPath, rawConfig, opts) {
|
|
|
118
109
|
return Promise.reject(e);
|
|
119
110
|
}
|
|
120
111
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (configFileName === void 0) { configFileName = "prh.yml"; }
|
|
124
|
-
var configFilePath = path.resolve(baseDir, configFileName);
|
|
112
|
+
function getRuleFilePath(baseDir, configFileName = "prh.yml") {
|
|
113
|
+
const configFilePath = path.resolve(baseDir, configFileName);
|
|
125
114
|
if (fs.existsSync(configFilePath)) {
|
|
126
115
|
return configFilePath;
|
|
127
116
|
}
|
|
@@ -130,5 +119,4 @@ function getRuleFilePath(baseDir, configFileName) {
|
|
|
130
119
|
}
|
|
131
120
|
return getRuleFilePath(path.resolve(baseDir, "../"), configFileName);
|
|
132
121
|
}
|
|
133
|
-
exports.getRuleFilePath = getRuleFilePath;
|
|
134
122
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAUA,8CAMC;AAMD,4CAGC;AAED,4BAGC;AAED,sCA+CC;AAED,wDAMC;AAED,sDAMC;AAED,sCAMC;AAED,gDAMC;AAED,0CAWC;AA5HD,yBAAyB;AACzB,6BAA6B;AAC7B,gCAAgC;AAGhC,qCAAkC;AAGzB,uFAHA,eAAM,OAGA;AAFf,4CAA+C;AAE9B,0FAFR,qBAAS,OAEQ;AAAE,qFAFR,gBAAI,OAEQ;AAEhC,SAAgB,iBAAiB,CAAC,GAAG,WAAqB;IACtD,MAAM,MAAM,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACnC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAClB,CAAC;AAMD,SAAgB,gBAAgB,CAAC,UAAkB,EAAE,OAAgB,EAAE;IACnE,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAClE,O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OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;AACL,CAAC;AAED,SAAgB,aAAa,CAAC,UAAkB,EAAE,WAAmB,EAAE,OAAgB,EAAE;IACrF,IAAI,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;AACL,CAAC;AAED,SAAgB,kBAAkB,CAAC,UAAkB,EAAE,SAAqB,EAAE,OAAgB,EAAE;IAC5F,IAAI,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;AACL,CAAC;AAED,SAAgB,eAAe,CAAC,OAAe,EAAE,cAAc,GAAG,SAAS;IACvE,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IAC7D,IAAI,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,OAAO,cAAc,CAAC;IAC1B,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QAClD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,cAAc,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import * as fs from \"fs\";\nimport * as path from \"path\";\nimport * as yaml from \"js-yaml\";\n\nimport * as raw from \"./raw\";\nimport { Engine } from \"./engine\";\nimport { ChangeSet, Diff } from \"./changeset/\";\n\nexport { Engine, ChangeSet, Diff };\n\nexport function fromYAMLFilePaths(...configPaths: string[]): Engine {\n const engine = fromYAMLFilePath(configPaths[0]);\n configPaths.splice(1).forEach((path) => {\n engine.merge(fromYAMLFilePath(path));\n });\n return engine;\n}\n\nexport interface Options {\n disableImports?: boolean;\n}\n\nexport function fromYAMLFilePath(configPath: string, opts: Options = {}): Engine {\n const content = fs.readFileSync(configPath, { encoding: \"utf8\" });\n return fromYAML(configPath, content, opts);\n}\n\nexport function fromYAML(configPath: string, yamlContent: string, opts: Options = {}): Engine {\n const rawConfig = yaml.load(yamlContent) as raw.Config;\n return fromRowConfig(configPath, rawConfig, opts);\n}\n\nexport function fromRowConfig(configPath: string, rawConfig: raw.Config, opts: Options = {}): Engine {\n const engine = new Engine(rawConfig);\n engine.sourcePaths.push(path.normalize(configPath));\n\n if (!opts.disableImports && rawConfig.imports) {\n // TODO この辺の処理をEngine側に移したい\n // なるべく破壊的変更を避ける\n // fsやyamlを使わずに同等のEngineを組み立てる余地を残す\n // async化したいけどprhの参照パッケージが壊れるのが辛い\n\n let importSpecs: raw.ImportSpec[];\n if (typeof rawConfig.imports === \"string\") {\n importSpecs = [\n {\n path: rawConfig.imports,\n },\n ];\n } else {\n importSpecs = rawConfig.imports.map((imp) => {\n if (typeof imp === \"string\") {\n return {\n path: imp,\n };\n }\n return imp;\n });\n }\n importSpecs.forEach((importSpec) => {\n const importedConfigPath = path.join(path.dirname(configPath), importSpec.path);\n const newEngine = fromYAMLFilePath(importedConfigPath, {\n disableImports: !!importSpec.disableImports,\n });\n\n const ignoreRules = (importSpec.ignoreRules || []).map((ignoreRule) => {\n return typeof ignoreRule === \"string\" ? { pattern: ignoreRule } : ignoreRule;\n });\n newEngine.rules = newEngine.rules.filter((rule) => {\n return ignoreRules.every((ignoreRule) => {\n return !rule._shouldIgnore(ignoreRule);\n });\n });\n\n engine.merge(newEngine);\n });\n }\n\n return engine;\n}\n\nexport function fromYAMLFilePathsAsync(...configPaths: string[]): Promise<Engine> {\n try {\n return Promise.resolve(fromYAMLFilePaths(...configPaths));\n } catch (e) {\n return Promise.reject(e);\n }\n}\n\nexport function fromYAMLFilePathAsync(configPath: string, opts: Options = {}): Promise<Engine> {\n try {\n return Promise.resolve(fromYAMLFilePath(configPath, opts));\n } catch (e) {\n return Promise.reject(e);\n }\n}\n\nexport function fromYAMLAsync(configPath: string, yamlContent: string, opts: Options = {}): Promise<Engine> {\n try {\n return Promise.resolve(fromYAML(configPath, yamlContent, opts));\n } catch (e) {\n return Promise.reject(e);\n }\n}\n\nexport function fromRowConfigAsync(configPath: string, rawConfig: raw.Config, opts: Options = {}): Promise<Engine> {\n try {\n return Promise.resolve(fromRowConfig(configPath, rawConfig, opts));\n } catch (e) {\n return Promise.reject(e);\n }\n}\n\nexport function getRuleFilePath(baseDir: string, configFileName = \"prh.yml\"): string | null {\n const configFilePath = path.resolve(baseDir, configFileName);\n if (fs.existsSync(configFilePath)) {\n return configFilePath;\n }\n\n if (baseDir.length === path.dirname(baseDir).length) {\n return null;\n }\n\n return getRuleFilePath(path.resolve(baseDir, \"../\"), configFileName);\n}\n"]}
|
package/lib/options.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.Options = void 0;
|
|
4
|
+
class Options {
|
|
5
|
+
constructor(_rule, src) {
|
|
5
6
|
src = src || {};
|
|
6
7
|
this.wordBoundary = src.wordBoundary != null ? src.wordBoundary : false;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
}());
|
|
9
|
+
}
|
|
10
10
|
exports.Options = Options;
|
|
11
11
|
//# sourceMappingURL=options.js.map
|
package/lib/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["options.ts"],"names":[],"mappings":";;;AAGA,MAAa,OAAO;IAGhB,YAAY,KAAW,EAAE,GAAiB;QACtC,GAAG,GAAG,GAAG,IAAI,EAAE,CAAC;QAChB,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5E,CAAC;CACJ;AAPD,0BAOC","sourcesContent":["import * as raw from \"./raw\";\nimport { Rule } from \"./rule\";\n\nexport class Options {\n wordBoundary: boolean;\n\n constructor(_rule: Rule, src?: raw.Options) {\n src = src || {};\n this.wordBoundary = src.wordBoundary != null ? src.wordBoundary : false;\n }\n}\n"]}
|
package/lib/paragraph.js
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Paragraph = void 0;
|
|
3
4
|
// 設計思想
|
|
4
5
|
// 文章の1ブロック毎にデータを保持する
|
|
5
6
|
// ファイル全体→Paragraphに分割→Paragraph毎にChangeSetを作成→ChangeSetをmerge
|
|
6
7
|
// Paragraphでは特定の検出を無効化したい場合がある
|
|
7
8
|
// 例えばてくぶ標準だと 良い→よい と変換するが漢字をわざと使いたい場合がある
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
class Paragraph {
|
|
10
|
+
constructor(index, content) {
|
|
10
11
|
this.index = index;
|
|
11
12
|
this.content = content;
|
|
12
13
|
this.ignoreAll = false;
|
|
13
14
|
// prh:disable:良い|悪い みたいなパターンからチェックをパスさせる表現を作る
|
|
14
15
|
// prh:disable だけの場合は全部パスさせる
|
|
15
|
-
|
|
16
|
+
const re = /^(?:.*?)prh:disable(?::([^\n\s]*))?/gm;
|
|
16
17
|
this._pragmaRanges = [];
|
|
17
18
|
this.ignorePatterns = [];
|
|
18
19
|
while (true) {
|
|
19
|
-
|
|
20
|
+
const matches = re.exec(content);
|
|
20
21
|
if (!matches) {
|
|
21
22
|
break;
|
|
22
23
|
}
|
|
@@ -25,27 +26,25 @@ var Paragraph = /** @class */ (function () {
|
|
|
25
26
|
this.ignoreAll = true;
|
|
26
27
|
continue;
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
+
const pattern = matches[1];
|
|
29
30
|
this._pragmaRanges.push({ index: matches.index, tailIndex: matches.index + matches[0].length });
|
|
30
|
-
this.ignorePatterns.push(new RegExp(
|
|
31
|
+
this.ignorePatterns.push(new RegExp(`(${pattern})`, "g"));
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var diffs = rules.map(function (rule) { return rule.applyRule(_this.content); }).reduce(function (p, c) { return p.concat(c); }, []);
|
|
34
|
+
makeDiffs(rules) {
|
|
35
|
+
let diffs = rules.map((rule) => rule.applyRule(this.content)).reduce((p, c) => p.concat(c), []);
|
|
36
36
|
// pragmaに被る範囲の検出は無視する
|
|
37
|
-
diffs = diffs.filter(
|
|
38
|
-
diffs.forEach(
|
|
37
|
+
diffs = diffs.filter((diff) => this._pragmaRanges.every((range) => !diff.isCollide(range)));
|
|
38
|
+
diffs.forEach((diff) => (diff.index += this.index));
|
|
39
39
|
if (this.ignoreAll) {
|
|
40
40
|
return [];
|
|
41
41
|
}
|
|
42
|
-
return diffs.filter(
|
|
43
|
-
return
|
|
42
|
+
return diffs.filter((diff) => {
|
|
43
|
+
return (this.ignorePatterns.filter((ignorePattern) => {
|
|
44
44
|
return diff.matches[0].match(ignorePattern);
|
|
45
|
-
}).length === 0;
|
|
45
|
+
}).length === 0);
|
|
46
46
|
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
50
49
|
exports.Paragraph = Paragraph;
|
|
51
50
|
//# sourceMappingURL=paragraph.js.map
|
package/lib/paragraph.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paragraph.js","sourceRoot":"","sources":["paragraph.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"paragraph.js","sourceRoot":"","sources":["paragraph.ts"],"names":[],"mappings":";;;AAGA,OAAO;AACP,qBAAqB;AACrB,8DAA8D;AAC9D,+BAA+B;AAC/B,2CAA2C;AAE3C,MAAa,SAAS;IAQlB,YAAY,KAAa,EAAE,OAAe;QACtC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QAEvB,8CAA8C;QAC9C,4BAA4B;QAC5B,MAAM,EAAE,GAAG,uCAAuC,CAAC;QACnD,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,OAAO,IAAI,EAAE,CAAC;YACV,MAAM,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,MAAM;YACV,CAAC;YACD,UAAU;YACV,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;gBACd,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;gBACtB,SAAS;YACb,CAAC;YAED,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAChG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;IACL,CAAC;IAED,SAAS,CAAC,KAAa;QACnB,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChG,sBAAsB;QACtB,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAE5F,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAEpD,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,OAAO,EAAE,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACzB,OAAO,CACH,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,EAAE;gBACzC,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAClB,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAtDD,8BAsDC","sourcesContent":["import { Rule } from \"./rule\";\nimport { Diff } from \"./changeset/diff\";\n\n// 設計思想\n// 文章の1ブロック毎にデータを保持する\n// ファイル全体→Paragraphに分割→Paragraph毎にChangeSetを作成→ChangeSetをmerge\n// Paragraphでは特定の検出を無効化したい場合がある\n// 例えばてくぶ標準だと 良い→よい と変換するが漢字をわざと使いたい場合がある\n\nexport class Paragraph {\n index: number;\n content: string;\n ignoreAll: boolean;\n /* @internal */\n _pragmaRanges: { index: number; tailIndex: number }[];\n ignorePatterns: RegExp[];\n\n constructor(index: number, content: string) {\n this.index = index;\n this.content = content;\n this.ignoreAll = false;\n\n // prh:disable:良い|悪い みたいなパターンからチェックをパスさせる表現を作る\n // prh:disable だけの場合は全部パスさせる\n const re = /^(?:.*?)prh:disable(?::([^\\n\\s]*))?/gm;\n this._pragmaRanges = [];\n this.ignorePatterns = [];\n while (true) {\n const matches = re.exec(content);\n if (!matches) {\n break;\n }\n // : の後の有無\n if (!matches[1]) {\n this.ignoreAll = true;\n continue;\n }\n\n const pattern = matches[1];\n this._pragmaRanges.push({ index: matches.index, tailIndex: matches.index + matches[0].length });\n this.ignorePatterns.push(new RegExp(`(${pattern})`, \"g\"));\n }\n }\n\n makeDiffs(rules: Rule[]): Diff[] {\n let diffs = rules.map((rule) => rule.applyRule(this.content)).reduce((p, c) => p.concat(c), []);\n // pragmaに被る範囲の検出は無視する\n diffs = diffs.filter((diff) => this._pragmaRanges.every((range) => !diff.isCollide(range)));\n\n diffs.forEach((diff) => (diff.index += this.index));\n\n if (this.ignoreAll) {\n return [];\n }\n\n return diffs.filter((diff) => {\n return (\n this.ignorePatterns.filter((ignorePattern) => {\n return diff.matches[0].match(ignorePattern);\n }).length === 0\n );\n });\n }\n}\n"]}
|
package/lib/raw.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw.js","sourceRoot":"","sources":["raw.ts"],"names":[],"mappings":"","sourcesContent":["export interface Config {\n version: number;\n imports?: string | (string | ImportSpec)[];\n targets?: Target[];\n rules?: (string | Rule)[]; // string | regexp style string or array\n}\n\nexport interface ImportSpec {\n path: string;\n disableImports?: boolean;\n // when string
|
|
1
|
+
{"version":3,"file":"raw.js","sourceRoot":"","sources":["raw.ts"],"names":[],"mappings":"","sourcesContent":["export interface Config {\n version: number;\n imports?: string | (string | ImportSpec)[];\n targets?: Target[];\n rules?: (string | Rule)[]; // string | regexp style string or array\n}\n\nexport interface ImportSpec {\n path: string;\n disableImports?: boolean;\n // when string coming, evaluate to { pattern: string; }\n ignoreRules?: (string | IgnoreRule)[];\n}\n\nexport interface IgnoreRule {\n pattern?: string;\n expected?: string;\n}\n\nexport interface Target {\n file: string; // string | regexp style string\n includes?: (string | TargetPattern)[];\n excludes?: (string | TargetPattern)[];\n}\n\nexport interface TargetPattern {\n pattern: string; // string | regexp style string\n}\n\nexport interface Rule {\n expected: string;\n pattern?: string | string[] | null; // string | regexp style string or array\n patterns?: string | string[] | null; // string | regexp style string or array\n regexpMustEmpty?: string;\n options?: Options;\n specs?: RuleSpec[];\n}\n\nexport interface Options {\n wordBoundary?: boolean;\n}\n\nexport interface RuleSpec {\n from: string;\n to: string;\n}\n"]}
|