@effect-app/eslint-shared-config 0.0.4 → 0.0.7
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 +21 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/LICENSE +21 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/README.md +215 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/configs/disable-conflict-rules.d.ts +110 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/configs/disable-conflict-rules.js +114 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/configs/disable-conflict-rules.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/configs/recommended.d.ts +159 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/configs/recommended.js +60 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/configs/recommended.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/dockerfile-config-schema.json +52 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/dprint.d.ts +8 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/dprint.js +188 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/dprint.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/graphql-config-schema.json +255 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/json-config-schema.json +187 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/malva-config-schema.json +363 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/markdown-config-schema.json +187 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/markup-config-schema.json +534 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/toml-config-schema.json +125 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/typescript-config-schema.json +1898 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/dprint/yaml-config-schema.json +126 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/index.d.ts +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/index.js +21 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/index.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/rules/dprint.d.ts +4 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/rules/dprint.js +261 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/rules/dprint.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/util/difference-iterator.d.ts +49 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/util/difference-iterator.js +129 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/util/difference-iterator.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/util/predicate.d.ts +10 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/util/predicate.js +20 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/dist/lib/util/predicate.js.map +1 -0
- package/node_modules/@ben_12/eslint-plugin-dprint/package.json +122 -0
- package/package.json +8 -2
- package/patches/@ben_12+eslint-plugin-dprint+1.7.5.patch +39 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Config",
|
|
3
|
+
"description": "Configuration for dprint-plugin-yaml.",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"definitions": {
|
|
6
|
+
"preferSingleLine": {
|
|
7
|
+
"description": "Control whether items should be placed on single line as possible, even they're originally on multiple lines.",
|
|
8
|
+
"type": "boolean"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"properties": {
|
|
12
|
+
"printWidth": {
|
|
13
|
+
"description": "The line width limitation that Pretty YAML should *(but not must)* avoid exceeding. Pretty YAML will try its best to keep line width less than this value, but it may exceed for some cases, for example, a very very long single word.",
|
|
14
|
+
"type": "integer",
|
|
15
|
+
"minimum": 0
|
|
16
|
+
},
|
|
17
|
+
"indentWidth": {
|
|
18
|
+
"description": "Size of indentation.",
|
|
19
|
+
"type": "integer",
|
|
20
|
+
"minimum": 0
|
|
21
|
+
},
|
|
22
|
+
"lineBreak": {
|
|
23
|
+
"description": "Specify whether use `\\n` (LF) or `\\r\\n` (CRLF) for line break.",
|
|
24
|
+
"type": "string",
|
|
25
|
+
"enum": [
|
|
26
|
+
"lf",
|
|
27
|
+
"crlf"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"quotes": {
|
|
31
|
+
"description": "Control the quotes.",
|
|
32
|
+
"type": "string",
|
|
33
|
+
"oneOf": [
|
|
34
|
+
{
|
|
35
|
+
"description": "Use double quotes as possible. However if there're quotes or escaped characters in strings, quotes will be kept as-is.",
|
|
36
|
+
"type": "string",
|
|
37
|
+
"enum": [
|
|
38
|
+
"preferDouble"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"description": "Use single quotes as possible. However if there're quotes or `\\` characters in strings, quotes will be kept as-is.",
|
|
43
|
+
"type": "string",
|
|
44
|
+
"enum": [
|
|
45
|
+
"preferSingle"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"description": "Use double quotes as possible. However if there're escaped characters in strings, quotes will be kept as-is.",
|
|
50
|
+
"type": "string",
|
|
51
|
+
"enum": [
|
|
52
|
+
"forceDouble"
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"description": "Use single quotes as possible. However if there're `\\` char or `\"` char in strings, quotes will be kept as-is.",
|
|
57
|
+
"type": "string",
|
|
58
|
+
"enum": [
|
|
59
|
+
"forceSingle"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"trailingComma": {
|
|
65
|
+
"description": "Control whether trailing comma should be inserted or not.",
|
|
66
|
+
"type": "boolean"
|
|
67
|
+
},
|
|
68
|
+
"formatComments": {
|
|
69
|
+
"description": "Control whether whitespace should be inserted at the beginning of comments or not.",
|
|
70
|
+
"type": "boolean"
|
|
71
|
+
},
|
|
72
|
+
"indentBlockSequenceInMap": {
|
|
73
|
+
"description": "Control whether block sequence should be indented or not in a block map.",
|
|
74
|
+
"type": "boolean"
|
|
75
|
+
},
|
|
76
|
+
"braceSpacing": {
|
|
77
|
+
"description": "Control whether whitespace should be inserted between braces or not.",
|
|
78
|
+
"type": "boolean"
|
|
79
|
+
},
|
|
80
|
+
"bracketSpacing": {
|
|
81
|
+
"description": "Control whether whitespace should be inserted between brackets or not.",
|
|
82
|
+
"type": "boolean"
|
|
83
|
+
},
|
|
84
|
+
"dashSpacing": {
|
|
85
|
+
"description": "Control the whitespace behavior of block compact map in block sequence value. This option is only effective when `indentWidth` is greater than 2.",
|
|
86
|
+
"type": "string",
|
|
87
|
+
"oneOf": [
|
|
88
|
+
{
|
|
89
|
+
"description": "Insert only one space after `-`.",
|
|
90
|
+
"type": "string",
|
|
91
|
+
"enum": [
|
|
92
|
+
"oneSpace"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"description": "Insert spaces to align indentation, respecting `indentWidth` option.",
|
|
97
|
+
"type": "string",
|
|
98
|
+
"enum": [
|
|
99
|
+
"indent"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
"preferSingleLine": {
|
|
105
|
+
"$ref": "#/definitions/preferSingleLine"
|
|
106
|
+
},
|
|
107
|
+
"flowSequence.preferSingleLine": {
|
|
108
|
+
"$ref": "#/definitions/preferSingleLine"
|
|
109
|
+
},
|
|
110
|
+
"flowMap.preferSingleLine": {
|
|
111
|
+
"$ref": "#/definitions/preferSingleLine"
|
|
112
|
+
},
|
|
113
|
+
"trimTrailingWhitespaces": {
|
|
114
|
+
"description": "Control whether trailing whitespaces should be trimmed or not.",
|
|
115
|
+
"type": "boolean"
|
|
116
|
+
},
|
|
117
|
+
"trimTrailingZero": {
|
|
118
|
+
"description": "Control whether trailing zeros should be removed or not.",
|
|
119
|
+
"type": "boolean"
|
|
120
|
+
},
|
|
121
|
+
"ignoreCommentDirective": {
|
|
122
|
+
"description": "Text directive for ignoring formatting specific content.",
|
|
123
|
+
"type": "string"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
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-typescript-conflict-rules": disable_conflict_rules_1.disableTypescriptConflictRules,
|
|
9
|
+
"dockerfile-recommended": recommended_1.dockerfileRecommended,
|
|
10
|
+
"json-recommended": recommended_1.jsonRecommended,
|
|
11
|
+
"markdown-recommended": recommended_1.markdownRecommended,
|
|
12
|
+
"toml-recommended": recommended_1.tomlRecommended,
|
|
13
|
+
"typescript-recommended": recommended_1.typescriptRecommended,
|
|
14
|
+
"malva-recommended": recommended_1.malvaRecommended,
|
|
15
|
+
"markup-recommended": recommended_1.markupRecommended,
|
|
16
|
+
"yaml-recommended": recommended_1.yamlRecommended,
|
|
17
|
+
"graphql-recommended": recommended_1.graphqlRecommended,
|
|
18
|
+
},
|
|
19
|
+
rules: dprint_1.dprintRules,
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;AAAA,6EAAiF;AACjF,uDAU8B;AAC9B,2CAA4C;AAE5C,MAAM,CAAC,OAAO,GAAG;IACb,OAAO,EAAE;QACL,mCAAmC,EAAE,uDAA8B;QACnE,wBAAwB,EAAE,mCAAqB;QAC/C,kBAAkB,EAAE,6BAAe;QACnC,sBAAsB,EAAE,iCAAmB;QAC3C,kBAAkB,EAAE,6BAAe;QACnC,wBAAwB,EAAE,mCAAqB;QAC/C,mBAAmB,EAAE,8BAAgB;QACrC,oBAAoB,EAAE,+BAAiB;QACvC,kBAAkB,EAAE,6BAAe;QACnC,qBAAqB,EAAE,gCAAkB;KAC5C;IACD,KAAK,EAAE,oBAAW;CACrB,CAAA"}
|
|
@@ -0,0 +1,261 @@
|
|
|
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.dprintRules = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const dockerfile_config_schema_json_1 = __importDefault(require("../dprint/dockerfile-config-schema.json"));
|
|
9
|
+
const dprint_1 = require("../dprint/dprint");
|
|
10
|
+
const graphql_config_schema_json_1 = __importDefault(require("../dprint/graphql-config-schema.json"));
|
|
11
|
+
const json_config_schema_json_1 = __importDefault(require("../dprint/json-config-schema.json"));
|
|
12
|
+
const malva_config_schema_json_1 = __importDefault(require("../dprint/malva-config-schema.json"));
|
|
13
|
+
const markdown_config_schema_json_1 = __importDefault(require("../dprint/markdown-config-schema.json"));
|
|
14
|
+
const markup_config_schema_json_1 = __importDefault(require("../dprint/markup-config-schema.json"));
|
|
15
|
+
const toml_config_schema_json_1 = __importDefault(require("../dprint/toml-config-schema.json"));
|
|
16
|
+
const typescript_config_schema_json_1 = __importDefault(require("../dprint/typescript-config-schema.json"));
|
|
17
|
+
const yaml_config_schema_json_1 = __importDefault(require("../dprint/yaml-config-schema.json"));
|
|
18
|
+
const difference_iterator_1 = require("../util/difference-iterator");
|
|
19
|
+
const predicate_1 = require("../util/predicate");
|
|
20
|
+
const configSchemas = [
|
|
21
|
+
{ name: "dockerfile", configSchema: dockerfile_config_schema_json_1.default },
|
|
22
|
+
{ name: "json", configSchema: json_config_schema_json_1.default },
|
|
23
|
+
{ name: "markdown", configSchema: markdown_config_schema_json_1.default },
|
|
24
|
+
{ name: "toml", configSchema: toml_config_schema_json_1.default },
|
|
25
|
+
{ name: "typescript", configSchema: typescript_config_schema_json_1.default },
|
|
26
|
+
{ name: "malva", configSchema: malva_config_schema_json_1.default },
|
|
27
|
+
{ name: "markup", configSchema: markup_config_schema_json_1.default },
|
|
28
|
+
{ name: "yaml", configSchema: yaml_config_schema_json_1.default },
|
|
29
|
+
{ name: "graphql", configSchema: graphql_config_schema_json_1.default },
|
|
30
|
+
];
|
|
31
|
+
const messages = {
|
|
32
|
+
requireLinebreak: "Require line break(s).",
|
|
33
|
+
extraLinebreak: "Extra line break(s).",
|
|
34
|
+
requireWhitespace: "Require whitespace(s).",
|
|
35
|
+
extraWhitespace: "Extra whitespace(s).",
|
|
36
|
+
requireCode: "Require code {{text}}.",
|
|
37
|
+
extraCode: "Extra code {{text}}.",
|
|
38
|
+
replaceWhitespace: "Require tweaking whitespace(s).",
|
|
39
|
+
replaceCode: "Require code {{newText}} instead of {{oldText}}.",
|
|
40
|
+
moveCodeToNextLine: "Move code {{text}} to the next line.",
|
|
41
|
+
moveCodeToPrevLine: "Move code {{text}} to the previous line.",
|
|
42
|
+
moveCode: "Require tweaking whitespaces around code {{text}}.",
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Count line breaks in the head whitespace sequence.
|
|
46
|
+
* @param s The text to check.
|
|
47
|
+
*/
|
|
48
|
+
function getLineNumberOfFirstCode(s) {
|
|
49
|
+
const m = /^\s+/u.exec(s);
|
|
50
|
+
if (!m) {
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
const Linebreak = /\r\n|[\r\n]/gu;
|
|
54
|
+
let count = 0;
|
|
55
|
+
while (Linebreak.exec(m[0]) != null) {
|
|
56
|
+
count += 1;
|
|
57
|
+
}
|
|
58
|
+
return count;
|
|
59
|
+
}
|
|
60
|
+
function isAddDiff(d) {
|
|
61
|
+
return d.type === "add";
|
|
62
|
+
}
|
|
63
|
+
function isRemoveDiff(d) {
|
|
64
|
+
return d.type === "remove";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create the report message of a given add difference.
|
|
68
|
+
* @param d The add difference object to create message.
|
|
69
|
+
*/
|
|
70
|
+
function createAddMessage(d) {
|
|
71
|
+
if ((0, predicate_1.isWhitespace)(d.newText)) {
|
|
72
|
+
return {
|
|
73
|
+
messageId: (0, predicate_1.hasLinebreak)(d.newText)
|
|
74
|
+
? "requireLinebreak"
|
|
75
|
+
: "requireWhitespace",
|
|
76
|
+
data: {},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
messageId: "requireCode",
|
|
81
|
+
data: { text: JSON.stringify(d.newText.trim()) },
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create the report message of a given remove difference.
|
|
86
|
+
* @param d The remove difference object to create message.
|
|
87
|
+
*/
|
|
88
|
+
function createRemoveMessage(d) {
|
|
89
|
+
if ((0, predicate_1.isWhitespace)(d.oldText)) {
|
|
90
|
+
return {
|
|
91
|
+
messageId: (0, predicate_1.hasLinebreak)(d.oldText)
|
|
92
|
+
? "extraLinebreak"
|
|
93
|
+
: "extraWhitespace",
|
|
94
|
+
data: {},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
messageId: "extraCode",
|
|
99
|
+
data: { text: JSON.stringify(d.oldText.trim()) },
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create the report message of a given replace difference if is whitespace difference.
|
|
104
|
+
* @param d The replace difference object to create message.
|
|
105
|
+
*/
|
|
106
|
+
function createWhitespaceMessage(d) {
|
|
107
|
+
if ((0, predicate_1.isWhitespace)(d.oldText) && (0, predicate_1.isWhitespace)(d.newText)) {
|
|
108
|
+
const oldHasLinebreak = (0, predicate_1.hasLinebreak)(d.oldText);
|
|
109
|
+
const newHasLinebreak = (0, predicate_1.hasLinebreak)(d.newText);
|
|
110
|
+
if (!oldHasLinebreak && newHasLinebreak) {
|
|
111
|
+
return {
|
|
112
|
+
messageId: "requireLinebreak",
|
|
113
|
+
data: {},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
messageId: oldHasLinebreak && !newHasLinebreak
|
|
118
|
+
? "extraLinebreak"
|
|
119
|
+
: "replaceWhitespace",
|
|
120
|
+
data: {},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Create the report message of a given replace difference if is moved code difference.
|
|
127
|
+
* @param d The replace difference object to create message.
|
|
128
|
+
*/
|
|
129
|
+
function createMoveMessage(d) {
|
|
130
|
+
if (d.oldText.trim() === d.newText.trim()) {
|
|
131
|
+
const oldLine = getLineNumberOfFirstCode(d.oldText);
|
|
132
|
+
const newLine = getLineNumberOfFirstCode(d.newText);
|
|
133
|
+
if (newLine > oldLine) {
|
|
134
|
+
return {
|
|
135
|
+
messageId: "moveCodeToNextLine",
|
|
136
|
+
data: { text: JSON.stringify(d.oldText.trim()) },
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
messageId: newLine < oldLine
|
|
141
|
+
? "moveCodeToPrevLine"
|
|
142
|
+
: "moveCode",
|
|
143
|
+
data: { text: JSON.stringify(d.oldText.trim()) },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create the report message of a given replace difference.
|
|
150
|
+
* @param d The replace difference object to create message.
|
|
151
|
+
*/
|
|
152
|
+
function createRepaceMessage(d) {
|
|
153
|
+
return {
|
|
154
|
+
messageId: "replaceCode",
|
|
155
|
+
data: {
|
|
156
|
+
newText: JSON.stringify(d.newText),
|
|
157
|
+
oldText: JSON.stringify(d.oldText),
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Create the report message of a given difference.
|
|
163
|
+
* @param d The difference object to create message.
|
|
164
|
+
*/
|
|
165
|
+
function createMessage(d) {
|
|
166
|
+
if (isAddDiff(d)) {
|
|
167
|
+
return createAddMessage(d);
|
|
168
|
+
}
|
|
169
|
+
if (isRemoveDiff(d)) {
|
|
170
|
+
return createRemoveMessage(d);
|
|
171
|
+
}
|
|
172
|
+
return createWhitespaceMessage(d) ||
|
|
173
|
+
createMoveMessage(d) ||
|
|
174
|
+
createRepaceMessage(d);
|
|
175
|
+
}
|
|
176
|
+
const defaultOptions = { configFile: "dprint.json", config: {} };
|
|
177
|
+
exports.dprintRules = configSchemas.map((config) => ({
|
|
178
|
+
[config.name]: {
|
|
179
|
+
meta: {
|
|
180
|
+
docs: {
|
|
181
|
+
description: `Format ${config.name} with dprint`,
|
|
182
|
+
url: `https://github.com/ben12/eslint-plugin-dprint/blob/master/docs/rules/dprint-${config.name}.md`,
|
|
183
|
+
recommended: true,
|
|
184
|
+
},
|
|
185
|
+
fixable: "code",
|
|
186
|
+
messages,
|
|
187
|
+
schema: {
|
|
188
|
+
definitions: config.configSchema.definitions,
|
|
189
|
+
type: "array",
|
|
190
|
+
items: [{
|
|
191
|
+
type: "object",
|
|
192
|
+
properties: {
|
|
193
|
+
configFile: {
|
|
194
|
+
type: "string",
|
|
195
|
+
default: "dprint.json",
|
|
196
|
+
description: "dprint configuration file (default 'dprint.json')",
|
|
197
|
+
},
|
|
198
|
+
config: {
|
|
199
|
+
type: "object",
|
|
200
|
+
properties: config.configSchema.properties,
|
|
201
|
+
additionalProperties: false,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
additionalProperties: false,
|
|
205
|
+
}],
|
|
206
|
+
additionalItems: false,
|
|
207
|
+
},
|
|
208
|
+
type: "layout",
|
|
209
|
+
},
|
|
210
|
+
create: (context) => ({
|
|
211
|
+
Program() {
|
|
212
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
213
|
+
const filePath = context.filename ?? context.getFilename();
|
|
214
|
+
const fileText = sourceCode.getText();
|
|
215
|
+
const options = context.options[0] ?? defaultOptions;
|
|
216
|
+
const configFile = options.configFile ?? "dprint.json";
|
|
217
|
+
const configOpt = options.config || {};
|
|
218
|
+
// Needs an absolute path
|
|
219
|
+
if (!filePath || !path_1.default.isAbsolute(filePath)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// Does format
|
|
223
|
+
const formattedText = (0, dprint_1.format)(configFile, configOpt, filePath, fileText, config.name);
|
|
224
|
+
if (typeof formattedText !== "string") {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
generateLintReports(fileText, formattedText, sourceCode, context);
|
|
228
|
+
},
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
})).reduce((r1, r2) => ({ ...r1, ...r2 }), {});
|
|
232
|
+
function generateLintReports(fileText, formattedText, sourceCode, context) {
|
|
233
|
+
for (const d of difference_iterator_1.DifferenceIterator.iterate(fileText, formattedText)) {
|
|
234
|
+
const loc = d.type === "add"
|
|
235
|
+
? {
|
|
236
|
+
start: sourceCode.getLocFromIndex(d.range[0]),
|
|
237
|
+
end: sourceCode.getLocFromIndex(d.range[0]),
|
|
238
|
+
}
|
|
239
|
+
: {
|
|
240
|
+
start: sourceCode.getLocFromIndex(d.range[0]),
|
|
241
|
+
end: sourceCode.getLocFromIndex(d.range[1]),
|
|
242
|
+
};
|
|
243
|
+
const { messageId, data } = createMessage(d);
|
|
244
|
+
context.report({
|
|
245
|
+
loc,
|
|
246
|
+
messageId,
|
|
247
|
+
data,
|
|
248
|
+
fix(fixer) {
|
|
249
|
+
const range = d.range;
|
|
250
|
+
if (d.type === "add") {
|
|
251
|
+
return fixer.insertTextAfterRange(range, d.newText);
|
|
252
|
+
}
|
|
253
|
+
if (d.type === "remove") {
|
|
254
|
+
return fixer.removeRange(range);
|
|
255
|
+
}
|
|
256
|
+
return fixer.replaceTextRange(range, d.newText);
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=dprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dprint.js","sourceRoot":"","sources":["../../../lib/rules/dprint.ts"],"names":[],"mappings":";;;;;;AAEA,gDAAuB;AACvB,4GAA4E;AAC5E,6CAAyC;AACzC,sGAAsE;AACtE,gGAAgE;AAChE,kGAAkE;AAClE,wGAAwE;AACxE,oGAAoE;AACpE,gGAAgE;AAChE,4GAAoE;AACpE,gGAAgE;AAChE,qEAAwG;AACxG,iDAA8D;AAE9D,MAAM,aAAa,GAAG;IAClB,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,uCAAqC,EAAE;IAC3E,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,iCAA+B,EAAE;IAC/D,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,qCAAmC,EAAE;IACvE,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,iCAA+B,EAAE;IAC/D,EAAE,IAAI,EAAE,YAAY,EAAE,YAAY,EAAE,uCAA6B,EAAE;IACnE,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,kCAAgC,EAAE;IACjE,EAAE,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,mCAAiC,EAAE;IACnE,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,iCAA+B,EAAE;IAC/D,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,oCAAkC,EAAE;CACxE,CAAA;AAED,MAAM,QAAQ,GAA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AAK,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC7C,GAAG,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAC9C,CAAA;QACL,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAA;QAE5C,OAAO,CAAC,MAAM,CAAC;YACX,GAAG;YACH,SAAS;YACT,IAAI;YAEJ,GAAG,CAAC,KAAK;gBACL,MAAM,KAAK,GAAG,CAAC,CAAC,KAAyB,CAAA;gBACzC,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE;oBAClB,OAAO,KAAK,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;iBACtD;gBACD,IAAI,CAAC,CAAC,IAAI,KAAK,QAAQ,EAAE;oBACrB,OAAO,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;iBAClC;gBACD,OAAO,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;YACnD,CAAC;SACJ,CAAC,CAAA;KACL;AACL,CAAC"}
|
|
@@ -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(oldStr: string, newStr: 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,129 @@
|
|
|
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(oldStr, newStr) {
|
|
9
|
+
return new DifferenceIterator(oldStr, newStr).iterate();
|
|
10
|
+
}
|
|
11
|
+
/** All changes that the `diffChars()` function detected. */
|
|
12
|
+
changes;
|
|
13
|
+
/** The current index in `this.changes`. */
|
|
14
|
+
i = 0;
|
|
15
|
+
/** The current index in the original source code text. */
|
|
16
|
+
loc = 0;
|
|
17
|
+
/** Initialize this instance. */
|
|
18
|
+
constructor(oldStr, newStr) {
|
|
19
|
+
this.changes = (0, diff_1.diffChars)(oldStr, newStr);
|
|
20
|
+
}
|
|
21
|
+
/** Iterate differences. */
|
|
22
|
+
*iterate() {
|
|
23
|
+
while (this.i < this.changes.length) {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
|
+
const change = this.changeAt(this.i);
|
|
26
|
+
if (change.added) {
|
|
27
|
+
yield this.handleAdd(change);
|
|
28
|
+
}
|
|
29
|
+
else if (change.removed) {
|
|
30
|
+
yield this.handleRemove(change);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.i += 1;
|
|
34
|
+
this.loc += change.value.length;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Handle the current change (`current.added === true`). */
|
|
39
|
+
handleAdd(current) {
|
|
40
|
+
const next1 = this.changeAt(this.i + 1);
|
|
41
|
+
const next2 = this.changeAt(this.i + 2);
|
|
42
|
+
// Merge the sequence "added → removed" as a replacement.
|
|
43
|
+
if (next1?.removed) {
|
|
44
|
+
return this.newReplacedDiff(2, next1.value, current.value);
|
|
45
|
+
}
|
|
46
|
+
// Merge the following sequences as a replacement:
|
|
47
|
+
// - "added → as-is → added" and all of the three are whitespaces.
|
|
48
|
+
// - "added → as-is → removed" and the middle is whitespaces and the first and the last contains the same content.
|
|
49
|
+
if (next1 &&
|
|
50
|
+
next2 &&
|
|
51
|
+
!next1.added &&
|
|
52
|
+
!next1.removed &&
|
|
53
|
+
(0, predicate_1.isWhitespace)(next1.value)) {
|
|
54
|
+
// "added → as-is → added" and all of the three are whitespaces.
|
|
55
|
+
// It frequently appears as adding a line break with indentation.
|
|
56
|
+
if (next2.added &&
|
|
57
|
+
(0, predicate_1.isWhitespace)(current.value) &&
|
|
58
|
+
(0, predicate_1.isWhitespace)(next2.value)) {
|
|
59
|
+
return this.newReplacedDiff(3, next1.value, current.value + next1.value + next2.value);
|
|
60
|
+
}
|
|
61
|
+
// "added → as-is → removed" and the middle is whitespaces and the first and the last contains the same content.
|
|
62
|
+
// It frequently appears as moving code to the previous line.
|
|
63
|
+
if (next2.removed &&
|
|
64
|
+
current.value.trim().endsWith(next2.value.trim())) {
|
|
65
|
+
return this.newReplacedDiff(3, next1.value + next2.value, current.value + next1.value);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return this.newAddedDiff(1, current.value);
|
|
69
|
+
}
|
|
70
|
+
/** Handle the current change (`current.removed === true`). */
|
|
71
|
+
handleRemove(current) {
|
|
72
|
+
const next1 = this.changeAt(this.i + 1);
|
|
73
|
+
const next2 = this.changeAt(this.i + 2);
|
|
74
|
+
// Merge the sequence "removed → added" as a replacement.
|
|
75
|
+
if (next1?.added) {
|
|
76
|
+
return this.newReplacedDiff(2, current.value, next1.value);
|
|
77
|
+
}
|
|
78
|
+
// Merge the following sequences as a replacement:
|
|
79
|
+
// - "removed → as-is → removed" and all of the three are whitespaces.
|
|
80
|
+
// - "removed → as-is → added" and the middle is whitespaces and the first and the last contains the same content.
|
|
81
|
+
if (next1 &&
|
|
82
|
+
next2 &&
|
|
83
|
+
!next1.added &&
|
|
84
|
+
!next1.removed &&
|
|
85
|
+
(0, predicate_1.isWhitespace)(next1.value)) {
|
|
86
|
+
// "removed → as-is → removed" and all of the three are whitespaces.
|
|
87
|
+
// It frequently appears as removing a line break with indentation.
|
|
88
|
+
if (next2.removed &&
|
|
89
|
+
(0, predicate_1.isWhitespace)(current.value) &&
|
|
90
|
+
(0, predicate_1.isWhitespace)(next2.value)) {
|
|
91
|
+
return this.newReplacedDiff(3, current.value + next1.value + next2.value, next1.value);
|
|
92
|
+
}
|
|
93
|
+
// "removed → as-is → added" and the middle is whitespaces and the first and the last contains the same content.
|
|
94
|
+
// It frequently appears as moving code to the next line.
|
|
95
|
+
if (next2.added &&
|
|
96
|
+
next2.value.trim().startsWith(current.value.trim())) {
|
|
97
|
+
return this.newReplacedDiff(3, current.value + next1.value, next1.value + next2.value);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// It's a removal.
|
|
101
|
+
return this.newRemovedDiff(1, current.value);
|
|
102
|
+
}
|
|
103
|
+
/** Get the change at `i`. */
|
|
104
|
+
changeAt(i) {
|
|
105
|
+
return i >= 0 && i < this.changes.length ? this.changes[i] : undefined;
|
|
106
|
+
}
|
|
107
|
+
/** Create a diff object that type is `added`, and advance the cursor. */
|
|
108
|
+
newAddedDiff(numChanges, newText) {
|
|
109
|
+
const range = [this.loc, this.loc];
|
|
110
|
+
this.i += numChanges;
|
|
111
|
+
return { range, newText, oldText: undefined, type: "add" };
|
|
112
|
+
}
|
|
113
|
+
/** Create a diff object that type is `removed`, and advance the cursor. */
|
|
114
|
+
newRemovedDiff(numChanges, oldText) {
|
|
115
|
+
const range = [this.loc, this.loc + oldText.length];
|
|
116
|
+
this.i += numChanges;
|
|
117
|
+
this.loc += oldText.length;
|
|
118
|
+
return { range, newText: undefined, oldText, type: "remove" };
|
|
119
|
+
}
|
|
120
|
+
/** Create a diff object that type is `replaced`, and advance the cursor. */
|
|
121
|
+
newReplacedDiff(numChanges, oldText, newText) {
|
|
122
|
+
const range = [this.loc, this.loc + oldText.length];
|
|
123
|
+
this.i += numChanges;
|
|
124
|
+
this.loc += oldText.length;
|
|
125
|
+
return { range, newText, oldText, type: "replace" };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.DifferenceIterator = DifferenceIterator;
|
|
129
|
+
//# 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,M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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"}
|