@ben_12/eslint-plugin-dprint 0.6.0
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/LICENSE +21 -0
- package/README.md +76 -0
- package/lib/configs/disable-conflict-rules.d.ts +110 -0
- package/lib/configs/disable-conflict-rules.js +114 -0
- package/lib/configs/disable-conflict-rules.js.map +1 -0
- package/lib/configs/recommended.d.ts +111 -0
- package/lib/configs/recommended.js +9 -0
- package/lib/configs/recommended.js.map +1 -0
- package/lib/dprint/config-schema.json +1312 -0
- package/lib/dprint/typescript.d.ts +8 -0
- package/lib/dprint/typescript.js +122 -0
- package/lib/dprint/typescript.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/rules/dprint.d.ts +4 -0
- package/lib/rules/dprint.js +172 -0
- package/lib/rules/dprint.js.map +1 -0
- package/lib/util/difference-iterator.d.ts +49 -0
- package/lib/util/difference-iterator.js +127 -0
- package/lib/util/difference-iterator.js.map +1 -0
- package/lib/util/predicate.d.ts +10 -0
- package/lib/util/predicate.js +20 -0
- package/lib/util/predicate.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format the given text with the given config.
|
|
3
|
+
* @param config The config object.
|
|
4
|
+
* @param filePath The path to the file.
|
|
5
|
+
* @param fileText The content of the file.
|
|
6
|
+
* @returns The formatted text or undefined. It's undefined if the formatter doesn't change the text.
|
|
7
|
+
*/
|
|
8
|
+
export declare function format(config: Record<string, any>, filePath: string, fileText: string): string | undefined;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.format = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("debug"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const typescript_1 = __importDefault(require("@dprint/typescript"));
|
|
10
|
+
const debug = (0, debug_1.default)("eslint:plugin-dprint");
|
|
11
|
+
// Load `dprint-plugin-typescript`.
|
|
12
|
+
const TSPluginPath = typescript_1.default.getPath();
|
|
13
|
+
const TSPluginModule = new WebAssembly.Module(fs_1.default.readFileSync(TSPluginPath));
|
|
14
|
+
const TSPluginInstance = new WebAssembly.Instance(TSPluginModule, {});
|
|
15
|
+
const TSPlugin = TSPluginInstance.exports;
|
|
16
|
+
const BufferSize = TSPlugin.get_wasm_memory_buffer_size();
|
|
17
|
+
/** Cache to reduce copies of config values. */
|
|
18
|
+
let lastConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Format the given text with the given config.
|
|
21
|
+
* @param config The config object.
|
|
22
|
+
* @param filePath The path to the file.
|
|
23
|
+
* @param fileText The content of the file.
|
|
24
|
+
* @returns The formatted text or undefined. It's undefined if the formatter doesn't change the text.
|
|
25
|
+
*/
|
|
26
|
+
function format(config, filePath, fileText) {
|
|
27
|
+
if (config !== lastConfig) {
|
|
28
|
+
lastConfig = config;
|
|
29
|
+
writeConfig(config);
|
|
30
|
+
}
|
|
31
|
+
writeFilePath(filePath);
|
|
32
|
+
writeString(fileText);
|
|
33
|
+
const retv = TSPlugin.format();
|
|
34
|
+
switch (retv) {
|
|
35
|
+
case 0: // no change
|
|
36
|
+
return undefined;
|
|
37
|
+
case 1: // change
|
|
38
|
+
return readFormattedText();
|
|
39
|
+
case 2: // error
|
|
40
|
+
debug("FAILED TO FORMAT: %s", readErrorText());
|
|
41
|
+
return undefined;
|
|
42
|
+
default:
|
|
43
|
+
debug("FAILED TO FORMAT: Unknown response code (%d)", retv);
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.format = format;
|
|
48
|
+
/**
|
|
49
|
+
* Write the config to the plugin.
|
|
50
|
+
* @param config The config object.
|
|
51
|
+
*/
|
|
52
|
+
function writeConfig(config) {
|
|
53
|
+
TSPlugin.reset_config();
|
|
54
|
+
// The setting values must be strings.
|
|
55
|
+
const pluginConfig = {};
|
|
56
|
+
for (const [key, value] of Object.entries(config)) {
|
|
57
|
+
pluginConfig[key] = String(value);
|
|
58
|
+
}
|
|
59
|
+
writeString("{}");
|
|
60
|
+
TSPlugin.set_global_config();
|
|
61
|
+
writeString(JSON.stringify(pluginConfig));
|
|
62
|
+
TSPlugin.set_plugin_config();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Write the file path to the plugin.
|
|
66
|
+
* @param value The path to the file.
|
|
67
|
+
*/
|
|
68
|
+
function writeFilePath(value) {
|
|
69
|
+
writeString(value);
|
|
70
|
+
TSPlugin.set_file_path();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Read the text that the last `TSPlugin.format()` call formatted.
|
|
74
|
+
* @returns The formatted text.
|
|
75
|
+
*/
|
|
76
|
+
function readFormattedText() {
|
|
77
|
+
return readString(TSPlugin.get_formatted_text());
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Read the error message that the last `TSPlugin.format()` call caused.
|
|
81
|
+
* @returns The error message.
|
|
82
|
+
*/
|
|
83
|
+
function readErrorText() {
|
|
84
|
+
return readString(TSPlugin.get_error_text());
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Write a string to the plugin.
|
|
88
|
+
* @param text The text to write.
|
|
89
|
+
*/
|
|
90
|
+
function writeString(text) {
|
|
91
|
+
const buffer = Buffer.from(text, "utf8");
|
|
92
|
+
const length = buffer.byteLength;
|
|
93
|
+
TSPlugin.clear_shared_bytes(length);
|
|
94
|
+
let index = 0;
|
|
95
|
+
while (index < length) {
|
|
96
|
+
const writeCount = Math.min(length - index, BufferSize);
|
|
97
|
+
buffer.copy(new Uint8Array(TSPlugin
|
|
98
|
+
.memory
|
|
99
|
+
.buffer, TSPlugin.get_wasm_memory_buffer(), writeCount), 0, index, index + writeCount);
|
|
100
|
+
TSPlugin.add_to_shared_bytes_from_buffer(writeCount);
|
|
101
|
+
index += writeCount;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Read a text from the plugin.
|
|
106
|
+
* @param length The byte length of the string.
|
|
107
|
+
* @returns The read text.
|
|
108
|
+
*/
|
|
109
|
+
function readString(length) {
|
|
110
|
+
const buffer = Buffer.allocUnsafe(length);
|
|
111
|
+
let index = 0;
|
|
112
|
+
while (index < length) {
|
|
113
|
+
const readCount = Math.min(length - index, BufferSize);
|
|
114
|
+
TSPlugin.set_buffer_with_shared_bytes(index, readCount);
|
|
115
|
+
buffer.set(new Uint8Array(TSPlugin
|
|
116
|
+
.memory
|
|
117
|
+
.buffer, TSPlugin.get_wasm_memory_buffer(), readCount), index);
|
|
118
|
+
index += readCount;
|
|
119
|
+
}
|
|
120
|
+
return buffer.toString("utf8");
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../../lib/dprint/typescript.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA+B;AAC/B,4CAAmB;AACnB,oEAAuC;AAEvC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,sBAAsB,CAAC,CAAA;AAKjD,mCAAmC;AACnC,MAAM,YAAY,GAAG,oBAAM,CAAC,OAAO,EAAE,CAAA;AACrC,MAAM,cAAc,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,YAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAA;AAC5E,MAAM,gBAAgB,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;AACrE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,CAAA;AACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,2BAA2B,EAAE,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CAAC,MAAM,GAAG,KAAK,EAAE,UAAU,CAAC,CAAA;QACtD,QAAQ,CAAC,4BAA4B,CAAC,KAAK,EAAE,SAAS,CAAC,CAAA;QAEvD,MAAM,CAAC,GAAG,CACN,IAAI,UAAU,CACV,QAAQ;aACH,MAAM;aACN,MAAM,EACX,QAAQ,CAAC,sBAAsB,EAAE,EACjC,SAAS,CACZ,EACD,KAAK,CACR,CAAA;QAED,KAAK,IAAI,SAAS,CAAA;KACrB;IAED,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAClC,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const disable_conflict_rules_1 = require("./configs/disable-conflict-rules");
|
|
4
|
+
const recommended_1 = require("./configs/recommended");
|
|
5
|
+
const dprint_1 = require("./rules/dprint");
|
|
6
|
+
module.exports = {
|
|
7
|
+
configs: {
|
|
8
|
+
"disable-conflict-rules": disable_conflict_rules_1.disableConflictRules,
|
|
9
|
+
recommended: recommended_1.recommended,
|
|
10
|
+
},
|
|
11
|
+
rules: {
|
|
12
|
+
dprint: dprint_1.dprint,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;AAAA,6EAAuE;AACvE,uDAAmD;AACnD,2CAAuC;AAEvC,MAAM,CAAC,OAAO,GAAG;IACb,OAAO,EAAE;QACL,wBAAwB,EAAE,6CAAoB;QAC9C,WAAW,EAAX,yBAAW;KACd;IACD,KAAK,EAAE;QACH,MAAM,EAAN,eAAM;KACT;CACJ,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TSESLint } from "@typescript-eslint/utils";
|
|
2
|
+
export declare const dprint: TSESLint.RuleModule<"requireLinebreak" | "extraLinebreak" | "requireWhitespace" | "extraWhitespace" | "requireCode" | "extraCode" | "replaceWhitespace" | "replaceCode" | "moveCodeToNextLine" | "moveCodeToPrevLine" | "moveCode", {
|
|
3
|
+
config: {};
|
|
4
|
+
}[], TSESLint.RuleListener>;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.dprint = void 0;
|
|
7
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const config_schema_json_1 = __importDefault(require("../dprint/config-schema.json"));
|
|
10
|
+
const typescript_1 = require("../dprint/typescript");
|
|
11
|
+
const difference_iterator_1 = require("../util/difference-iterator");
|
|
12
|
+
const predicate_1 = require("../util/predicate");
|
|
13
|
+
const createRule = utils_1.ESLintUtils.RuleCreator(ruleName => `https://github.com/ben12/eslint-plugin-dprint/blob/master/docs/rules/${ruleName}.md`);
|
|
14
|
+
/**
|
|
15
|
+
* Count line breaks in the head whitespace sequence.
|
|
16
|
+
* @param s The text to check.
|
|
17
|
+
*/
|
|
18
|
+
function getLineNumberOfFirstCode(s) {
|
|
19
|
+
const m = /^\s+/u.exec(s);
|
|
20
|
+
if (!m) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
const Linebreak = /\r\n|[\r\n]/gu;
|
|
24
|
+
let count = 0;
|
|
25
|
+
while (Linebreak.exec(m[0]) != null) {
|
|
26
|
+
count += 1;
|
|
27
|
+
}
|
|
28
|
+
return count;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create the report message of a given difference.
|
|
32
|
+
* @param d The difference object to create message.
|
|
33
|
+
*/
|
|
34
|
+
function createMessage(d) {
|
|
35
|
+
if (d.type === "add") {
|
|
36
|
+
if ((0, predicate_1.isWhitespace)(d.newText)) {
|
|
37
|
+
return {
|
|
38
|
+
messageId: (0, predicate_1.hasLinebreak)(d.newText)
|
|
39
|
+
? "requireLinebreak"
|
|
40
|
+
: "requireWhitespace",
|
|
41
|
+
data: {},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
messageId: "requireCode",
|
|
46
|
+
data: { text: JSON.stringify(d.newText.trim()) },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (d.type === "remove") {
|
|
50
|
+
if ((0, predicate_1.isWhitespace)(d.oldText)) {
|
|
51
|
+
return {
|
|
52
|
+
messageId: (0, predicate_1.hasLinebreak)(d.oldText)
|
|
53
|
+
? "extraLinebreak"
|
|
54
|
+
: "extraWhitespace",
|
|
55
|
+
data: {},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
messageId: "extraCode",
|
|
60
|
+
data: { text: JSON.stringify(d.oldText.trim()) },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if ((0, predicate_1.isWhitespace)(d.oldText) && (0, predicate_1.isWhitespace)(d.newText)) {
|
|
64
|
+
const oldHasLinebreak = (0, predicate_1.hasLinebreak)(d.oldText);
|
|
65
|
+
const newHasLinebreak = (0, predicate_1.hasLinebreak)(d.newText);
|
|
66
|
+
return {
|
|
67
|
+
messageId: !oldHasLinebreak && newHasLinebreak
|
|
68
|
+
? "requireLinebreak"
|
|
69
|
+
: oldHasLinebreak && !newHasLinebreak
|
|
70
|
+
? "extraLinebreak"
|
|
71
|
+
: "replaceWhitespace",
|
|
72
|
+
data: {},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (d.oldText.trim() === d.newText.trim()) {
|
|
76
|
+
const oldLine = getLineNumberOfFirstCode(d.oldText);
|
|
77
|
+
const newLine = getLineNumberOfFirstCode(d.newText);
|
|
78
|
+
return {
|
|
79
|
+
messageId: newLine > oldLine
|
|
80
|
+
? "moveCodeToNextLine"
|
|
81
|
+
: newLine < oldLine
|
|
82
|
+
? "moveCodeToPrevLine"
|
|
83
|
+
: "moveCode",
|
|
84
|
+
data: { text: JSON.stringify(d.oldText.trim()) },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
messageId: "replaceCode",
|
|
89
|
+
data: {
|
|
90
|
+
newText: JSON.stringify(d.newText.trim()),
|
|
91
|
+
oldText: JSON.stringify(d.oldText.trim()),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
exports.dprint = createRule({
|
|
96
|
+
name: "dprint",
|
|
97
|
+
meta: {
|
|
98
|
+
docs: {
|
|
99
|
+
description: "Format code with dprint",
|
|
100
|
+
recommended: "recommended",
|
|
101
|
+
},
|
|
102
|
+
fixable: "code",
|
|
103
|
+
messages: {
|
|
104
|
+
requireLinebreak: "Require line break(s).",
|
|
105
|
+
extraLinebreak: "Extra line break(s).",
|
|
106
|
+
requireWhitespace: "Require whitespace(s).",
|
|
107
|
+
extraWhitespace: "Extra whitespace(s).",
|
|
108
|
+
requireCode: "Require code {{text}}.",
|
|
109
|
+
extraCode: "Extra code {{text}}.",
|
|
110
|
+
replaceWhitespace: "Require tweaking whitespace(s).",
|
|
111
|
+
replaceCode: "Require code {{newText}} instead of {{oldText}}.",
|
|
112
|
+
moveCodeToNextLine: "Move code {{text}} to the next line.",
|
|
113
|
+
moveCodeToPrevLine: "Move code {{text}} to the previous line.",
|
|
114
|
+
moveCode: "Require tweaking whitespaces around code {{text}}.",
|
|
115
|
+
},
|
|
116
|
+
schema: {
|
|
117
|
+
definitions: config_schema_json_1.default.definitions,
|
|
118
|
+
type: "array",
|
|
119
|
+
items: [{
|
|
120
|
+
type: "object",
|
|
121
|
+
properties: { config: config_schema_json_1.default },
|
|
122
|
+
additionalProperties: false,
|
|
123
|
+
}],
|
|
124
|
+
additionalItems: false,
|
|
125
|
+
},
|
|
126
|
+
type: "layout",
|
|
127
|
+
},
|
|
128
|
+
defaultOptions: [{ config: {} }],
|
|
129
|
+
create: (context, options) => ({
|
|
130
|
+
Program() {
|
|
131
|
+
const sourceCode = context.getSourceCode();
|
|
132
|
+
const filePath = context.getFilename();
|
|
133
|
+
const fileText = sourceCode.getText();
|
|
134
|
+
const config = options[0].config || {};
|
|
135
|
+
// Needs an absolute path
|
|
136
|
+
if (!filePath || !path_1.default.isAbsolute(filePath)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
// Does format
|
|
140
|
+
const formattedText = (0, typescript_1.format)(config, filePath, fileText);
|
|
141
|
+
if (typeof formattedText !== "string") {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
// Generate lint reports
|
|
145
|
+
for (const d of difference_iterator_1.DifferenceIterator.iterate(fileText, formattedText)) {
|
|
146
|
+
const loc = d.type === "add"
|
|
147
|
+
? sourceCode.getLocFromIndex(d.range[0])
|
|
148
|
+
: {
|
|
149
|
+
start: sourceCode.getLocFromIndex(d.range[0]),
|
|
150
|
+
end: sourceCode.getLocFromIndex(d.range[1]),
|
|
151
|
+
};
|
|
152
|
+
const { messageId, data } = createMessage(d);
|
|
153
|
+
context.report({
|
|
154
|
+
loc,
|
|
155
|
+
messageId,
|
|
156
|
+
data,
|
|
157
|
+
fix(fixer) {
|
|
158
|
+
const range = d.range;
|
|
159
|
+
if (d.type === "add") {
|
|
160
|
+
return fixer.insertTextAfterRange(range, d.newText);
|
|
161
|
+
}
|
|
162
|
+
if (d.type === "remove") {
|
|
163
|
+
return fixer.removeRange(range);
|
|
164
|
+
}
|
|
165
|
+
return fixer.replaceTextRange(range, d.newText);
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
//# sourceMappingURL=d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BAEJ,GAAG,CAAC,KAAK;wBACL,MAAM,KAAK,GAAG,CAAC,CAAC,KAAyB,CAAA;wBACzC,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE;4BAClB,OAAO,KAAK,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;yBACtD;wBACD,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE;4BACrB,OAAO,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;yBAClC;wBACD,OAAO,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;oBACnD,CAAC;iBACJ,CAAC,CAAA;aACL;QACL,CAAC;KACJ,CAAC;CACL,CAAC,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The difference type for add. */
|
|
2
|
+
export type AddDiff = {
|
|
3
|
+
type: "add";
|
|
4
|
+
range: readonly [number, number];
|
|
5
|
+
newText: string;
|
|
6
|
+
oldText: undefined;
|
|
7
|
+
};
|
|
8
|
+
/** The difference type for remove. */
|
|
9
|
+
export type RemoveDiff = {
|
|
10
|
+
type: "remove";
|
|
11
|
+
range: readonly [number, number];
|
|
12
|
+
newText: undefined;
|
|
13
|
+
oldText: string;
|
|
14
|
+
};
|
|
15
|
+
/** The difference type for replace. */
|
|
16
|
+
export type ReplaceDiff = {
|
|
17
|
+
type: "replace";
|
|
18
|
+
range: readonly [number, number];
|
|
19
|
+
newText: string;
|
|
20
|
+
oldText: string;
|
|
21
|
+
};
|
|
22
|
+
/** The difference type. */
|
|
23
|
+
export type Diff = AddDiff | RemoveDiff | ReplaceDiff;
|
|
24
|
+
/** The defference iterator. */
|
|
25
|
+
export declare class DifferenceIterator {
|
|
26
|
+
static iterate(s0: string, s1: string): Generator<Diff>;
|
|
27
|
+
/** All changes that the `diffChars()` function detected. */
|
|
28
|
+
private readonly changes;
|
|
29
|
+
/** The current index in `this.changes`. */
|
|
30
|
+
private i;
|
|
31
|
+
/** The current index in the original source code text. */
|
|
32
|
+
private loc;
|
|
33
|
+
/** Initialize this instance. */
|
|
34
|
+
private constructor();
|
|
35
|
+
/** Iterate differences. */
|
|
36
|
+
private iterate;
|
|
37
|
+
/** Handle the current change (`current.added === true`). */
|
|
38
|
+
private handleAdd;
|
|
39
|
+
/** Handle the current change (`current.removed === true`). */
|
|
40
|
+
private handleRemove;
|
|
41
|
+
/** Get the change at `i`. */
|
|
42
|
+
private changeAt;
|
|
43
|
+
/** Create a diff object that type is `added`, and advance the cursor. */
|
|
44
|
+
private newAddedDiff;
|
|
45
|
+
/** Create a diff object that type is `removed`, and advance the cursor. */
|
|
46
|
+
private newRemovedDiff;
|
|
47
|
+
/** Create a diff object that type is `replaced`, and advance the cursor. */
|
|
48
|
+
private newReplacedDiff;
|
|
49
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DifferenceIterator = void 0;
|
|
4
|
+
const diff_1 = require("diff");
|
|
5
|
+
const predicate_1 = require("./predicate");
|
|
6
|
+
/** The defference iterator. */
|
|
7
|
+
class DifferenceIterator {
|
|
8
|
+
static iterate(s0, s1) {
|
|
9
|
+
return new DifferenceIterator(s0, s1).iterate();
|
|
10
|
+
}
|
|
11
|
+
/** Initialize this instance. */
|
|
12
|
+
constructor(s0, s1) {
|
|
13
|
+
/** The current index in `this.changes`. */
|
|
14
|
+
this.i = 0;
|
|
15
|
+
/** The current index in the original source code text. */
|
|
16
|
+
this.loc = 0;
|
|
17
|
+
this.changes = (0, diff_1.diffChars)(s0, s1);
|
|
18
|
+
}
|
|
19
|
+
/** Iterate differences. */
|
|
20
|
+
*iterate() {
|
|
21
|
+
while (this.i < this.changes.length) {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
23
|
+
const change = this.changeAt(this.i);
|
|
24
|
+
if (change.added) {
|
|
25
|
+
yield this.handleAdd(change);
|
|
26
|
+
}
|
|
27
|
+
else if (change.removed) {
|
|
28
|
+
yield this.handleRemove(change);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.i += 1;
|
|
32
|
+
this.loc += change.value.length;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Handle the current change (`current.added === true`). */
|
|
37
|
+
handleAdd(current) {
|
|
38
|
+
const next1 = this.changeAt(this.i + 1);
|
|
39
|
+
const next2 = this.changeAt(this.i + 2);
|
|
40
|
+
// Merge the sequence "added → removed" as a replacement.
|
|
41
|
+
if (next1 && next1.removed) {
|
|
42
|
+
return this.newReplacedDiff(2, next1.value, current.value);
|
|
43
|
+
}
|
|
44
|
+
// Merge the following sequences as a replacement:
|
|
45
|
+
// - "added → as-is → added" and all of the three are whitespaces.
|
|
46
|
+
// - "added → as-is → removed" and the middle is whitespaces and the first and the last contains the same content.
|
|
47
|
+
if (next1 &&
|
|
48
|
+
next2 &&
|
|
49
|
+
!next1.added &&
|
|
50
|
+
!next1.removed &&
|
|
51
|
+
(0, predicate_1.isWhitespace)(next1.value)) {
|
|
52
|
+
// "added → as-is → added" and all of the three are whitespaces.
|
|
53
|
+
// It frequently appears as adding a line break with indentation.
|
|
54
|
+
if (next2.added &&
|
|
55
|
+
(0, predicate_1.isWhitespace)(current.value) &&
|
|
56
|
+
(0, predicate_1.isWhitespace)(next2.value)) {
|
|
57
|
+
return this.newReplacedDiff(3, next1.value, current.value + next1.value + next2.value);
|
|
58
|
+
}
|
|
59
|
+
// "added → as-is → removed" and the middle is whitespaces and the first and the last contains the same content.
|
|
60
|
+
// It frequently appears as moving code to the previous line.
|
|
61
|
+
if (next2.removed &&
|
|
62
|
+
current.value.trim().endsWith(next2.value.trim())) {
|
|
63
|
+
return this.newReplacedDiff(3, next1.value + next2.value, current.value + next1.value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return this.newAddedDiff(1, current.value);
|
|
67
|
+
}
|
|
68
|
+
/** Handle the current change (`current.removed === true`). */
|
|
69
|
+
handleRemove(current) {
|
|
70
|
+
const next1 = this.changeAt(this.i + 1);
|
|
71
|
+
const next2 = this.changeAt(this.i + 2);
|
|
72
|
+
// Merge the sequence "removed → added" as a replacement.
|
|
73
|
+
if (next1 && next1.added) {
|
|
74
|
+
return this.newReplacedDiff(2, current.value, next1.value);
|
|
75
|
+
}
|
|
76
|
+
// Merge the following sequences as a replacement:
|
|
77
|
+
// - "removed → as-is → removed" and all of the three are whitespaces.
|
|
78
|
+
// - "removed → as-is → added" and the middle is whitespaces and the first and the last contains the same content.
|
|
79
|
+
if (next1 &&
|
|
80
|
+
next2 &&
|
|
81
|
+
!next1.added &&
|
|
82
|
+
!next1.removed &&
|
|
83
|
+
(0, predicate_1.isWhitespace)(next1.value)) {
|
|
84
|
+
// "removed → as-is → removed" and all of the three are whitespaces.
|
|
85
|
+
// It frequently appears as removing a line break with indentation.
|
|
86
|
+
if (next2.removed &&
|
|
87
|
+
(0, predicate_1.isWhitespace)(current.value) &&
|
|
88
|
+
(0, predicate_1.isWhitespace)(next2.value)) {
|
|
89
|
+
return this.newReplacedDiff(3, current.value + next1.value + next2.value, next1.value);
|
|
90
|
+
}
|
|
91
|
+
// "removed → as-is → added" and the middle is whitespaces and the first and the last contains the same content.
|
|
92
|
+
// It frequently appears as moving code to the next line.
|
|
93
|
+
if (next2.added &&
|
|
94
|
+
next2.value.trim().startsWith(current.value.trim())) {
|
|
95
|
+
return this.newReplacedDiff(3, current.value + next1.value, next1.value + next2.value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// It's a removal.
|
|
99
|
+
return this.newRemovedDiff(1, current.value);
|
|
100
|
+
}
|
|
101
|
+
/** Get the change at `i`. */
|
|
102
|
+
changeAt(i) {
|
|
103
|
+
return i >= 0 && i < this.changes.length ? this.changes[i] : undefined;
|
|
104
|
+
}
|
|
105
|
+
/** Create a diff object that type is `added`, and advance the cursor. */
|
|
106
|
+
newAddedDiff(numChanges, newText) {
|
|
107
|
+
const range = [this.loc, this.loc];
|
|
108
|
+
this.i += numChanges;
|
|
109
|
+
return { range, newText, oldText: undefined, type: "add" };
|
|
110
|
+
}
|
|
111
|
+
/** Create a diff object that type is `removed`, and advance the cursor. */
|
|
112
|
+
newRemovedDiff(numChanges, oldText) {
|
|
113
|
+
const range = [this.loc, this.loc + oldText.length];
|
|
114
|
+
this.i += numChanges;
|
|
115
|
+
this.loc += oldText.length;
|
|
116
|
+
return { range, newText: undefined, oldText, type: "remove" };
|
|
117
|
+
}
|
|
118
|
+
/** Create a diff object that type is `replaced`, and advance the cursor. */
|
|
119
|
+
newReplacedDiff(numChanges, oldText, newText) {
|
|
120
|
+
const range = [this.loc, this.loc + oldText.length];
|
|
121
|
+
this.i += numChanges;
|
|
122
|
+
this.loc += oldText.length;
|
|
123
|
+
return { range, newText, oldText, type: "replace" };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.DifferenceIterator = DifferenceIterator;
|
|
127
|
+
//# sourceMappingURL=difference-iterator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"difference-iterator.js","sourceRoot":"","sources":["../../../lib/util/difference-iterator.ts"],"names":[],"mappings":";;;AAAA,+BAAwC;AACxC,2CAA0C;AA0B1C,+BAA+B;AAC/B,MAAa,kBAAkB;IACpB,MAAM,CAAC,OAAO,CAAC,EAAU,EAAE,EAAU;QACxC,OAAO,IAAI,kBAAkB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA;IACnD,CAAC;IASD,gCAAgC;IAChC,YAAoB,EAAU,EAAE,EAAU;QAN1C,2CAA2C;QACnC,MAAC,GAAG,CAAC,CAAA;QACb,0DAA0D;QAClD,QAAG,GAAG,CAAC,CAAA;QAIX,IAAI,CAAC,OAAO,GAAG,IAAA,gBAAS,EAAC,EAAE,EAAE,EAAE,CAAC,CAAA;IACpC,CAAC;IAED,2BAA2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CAAC,UAAkB,EAAE,OAAe;QACtD,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAU,CAAA;QAE5D,IAAI,CAAC,CAAC,IAAI,UAAU,CAAA;QACpB,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,MAAM,CAAA;QAE1B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;IACjE,CAAC;IAED,4EAA4E;IACpE,eAAe,CACnB,UAAkB,EAClB,OAAe,EACf,OAAe;QAEf,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,MAAM,CAAU,CAAA;QAE5D,IAAI,CAAC,CAAC,IAAI,UAAU,CAAA;QACpB,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,MAAM,CAAA;QAE1B,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAA;IACvD,CAAC;CACJ;AA9KD,gDA8KC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a given text is whitespace(s).
|
|
3
|
+
* @param s The text to check.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isWhitespace(s: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Check if a given text contains line break(s).
|
|
8
|
+
* @param s The text to check.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hasLinebreak(s: string): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasLinebreak = exports.isWhitespace = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if a given text is whitespace(s).
|
|
6
|
+
* @param s The text to check.
|
|
7
|
+
*/
|
|
8
|
+
function isWhitespace(s) {
|
|
9
|
+
return /^\s+$/u.test(s);
|
|
10
|
+
}
|
|
11
|
+
exports.isWhitespace = isWhitespace;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a given text contains line break(s).
|
|
14
|
+
* @param s The text to check.
|
|
15
|
+
*/
|
|
16
|
+
function hasLinebreak(s) {
|
|
17
|
+
return /[\r\n]/u.test(s);
|
|
18
|
+
}
|
|
19
|
+
exports.hasLinebreak = hasLinebreak;
|
|
20
|
+
//# sourceMappingURL=predicate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predicate.js","sourceRoot":"","sources":["../../../lib/util/predicate.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,SAAgB,YAAY,CAAC,CAAS;IAClC,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC3B,CAAC;AAFD,oCAEC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,CAAS;IAClC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC5B,CAAC;AAFD,oCAEC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ben_12/eslint-plugin-dprint",
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "An ESLint plugin that fixes code with dprint",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.0.0"
|
|
7
|
+
},
|
|
8
|
+
"main": "lib/index.js",
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"files": [
|
|
11
|
+
"lib"
|
|
12
|
+
],
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"eslint": ">=5.16.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@dprint/typescript": "^0.87.1",
|
|
18
|
+
"debug": "^4.1.1",
|
|
19
|
+
"diff": "^4.0.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@ben_12/eslint-plugin-dprint": "^0.6.0",
|
|
23
|
+
"@types/debug": "^4.1.5",
|
|
24
|
+
"@types/diff": "^5.0.0",
|
|
25
|
+
"@types/node": "^18.0.0",
|
|
26
|
+
"@types/rimraf": "^4.0.0",
|
|
27
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
28
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
29
|
+
"@typescript-eslint/utils": "^6.0.0",
|
|
30
|
+
"codecov": "^3.7.0",
|
|
31
|
+
"eslint": "^8.50.0",
|
|
32
|
+
"mocha": "^10.0.0",
|
|
33
|
+
"nyc": "^15.0.1",
|
|
34
|
+
"rimraf": "^5.0.0",
|
|
35
|
+
"shx": "^0.3.4",
|
|
36
|
+
"ts-node": "^10.0.0",
|
|
37
|
+
"typescript": "~5.0.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "rimraf dist && tsc -p tsconfig.build.json && shx cp \"{LICENSE,README.md,package.json}\" dist",
|
|
41
|
+
"codecov": "nyc report --reporter text-lcov | codecov --pipe --disable=gcov",
|
|
42
|
+
"lint": "eslint --rulesdir scripts/internal-rules \"**/*.ts\"",
|
|
43
|
+
"test": "npm run -s lint && npm run -s test:ci",
|
|
44
|
+
"test:ci": "tsc && nyc mocha \"test/rules/**/*.ts\"",
|
|
45
|
+
"watch": "mocha --require ts-node/register --watch --watch-files \"lib/**/*.ts,test/**/*.ts\" \"test/rules/**/*.ts\"",
|
|
46
|
+
"preversion": "npm test",
|
|
47
|
+
"version": "npm run -s build",
|
|
48
|
+
"postversion": "ts-node scripts/release"
|
|
49
|
+
},
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/ben12/eslint-plugin-dprint.git"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"eslint",
|
|
56
|
+
"eslintplugin",
|
|
57
|
+
"dprint"
|
|
58
|
+
],
|
|
59
|
+
"author": "Toru Nagashima <public@ben12.dev>",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/ben12/eslint-plugin-dprint/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/ben12/eslint-plugin-dprint#readme",
|
|
65
|
+
"funding": "https://github.com/sponsors/ben12"
|
|
66
|
+
}
|