@ben_12/eslint-plugin-dprint 0.7.0 → 0.8.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/README.md +54 -14
- package/dist/lib/configs/disable-conflict-rules.d.ts +1 -1
- package/dist/lib/configs/disable-conflict-rules.js +2 -2
- package/dist/lib/configs/disable-conflict-rules.js.map +1 -1
- package/dist/lib/configs/recommended.d.ts +26 -2
- package/dist/lib/configs/recommended.js +27 -3
- package/dist/lib/configs/recommended.js.map +1 -1
- package/dist/lib/dprint/dockerfile-config-schema.json +52 -0
- package/dist/lib/dprint/dprint.js +125 -0
- package/dist/lib/dprint/dprint.js.map +1 -0
- package/dist/lib/dprint/json-config-schema.json +158 -0
- package/dist/lib/dprint/markdown-config-schema.json +167 -0
- package/dist/lib/dprint/toml-config-schema.json +125 -0
- package/dist/lib/dprint/{config-schema.json → ts-config-schema.json} +1068 -466
- package/dist/lib/index.js +7 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/rules/dprint.d.ts +4 -5
- package/dist/lib/rules/dprint.js +193 -123
- package/dist/lib/rules/dprint.js.map +1 -1
- package/dist/lib/util/difference-iterator.d.ts +1 -1
- package/dist/lib/util/difference-iterator.js +6 -6
- package/dist/lib/util/difference-iterator.js.map +1 -1
- package/package.json +32 -8
- package/dist/lib/dprint/typescript.js +0 -166
- package/dist/lib/dprint/typescript.js.map +0 -1
- /package/dist/lib/dprint/{typescript.d.ts → dprint.d.ts} +0 -0
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.format = void 0;
|
|
30
|
-
const typescript_1 = __importDefault(require("@dprint/typescript"));
|
|
31
|
-
const debug_1 = __importDefault(require("debug"));
|
|
32
|
-
const fs_1 = __importDefault(require("fs"));
|
|
33
|
-
const JSONC = __importStar(require("jsonc-parser"));
|
|
34
|
-
const debug = (0, debug_1.default)("eslint:plugin-dprint");
|
|
35
|
-
// Load `dprint-plugin-typescript`.
|
|
36
|
-
const TSPluginPath = typescript_1.default.getPath();
|
|
37
|
-
const TSPluginModule = new WebAssembly.Module(fs_1.default.readFileSync(TSPluginPath));
|
|
38
|
-
const TSPluginInstance = new WebAssembly.Instance(TSPluginModule, {});
|
|
39
|
-
const TSPlugin = TSPluginInstance.exports;
|
|
40
|
-
const BufferSize = TSPlugin.get_wasm_memory_buffer_size();
|
|
41
|
-
/** Cache to reduce copies of config values. */
|
|
42
|
-
let lastConfig;
|
|
43
|
-
let lastConfigFile;
|
|
44
|
-
/**
|
|
45
|
-
* Format the given text with the given config.
|
|
46
|
-
* @param config The config object.
|
|
47
|
-
* @param filePath The path to the file.
|
|
48
|
-
* @param fileText The content of the file.
|
|
49
|
-
* @returns The formatted text or undefined. It's undefined if the formatter doesn't change the text.
|
|
50
|
-
*/
|
|
51
|
-
function format(configFile, config, filePath, fileText) {
|
|
52
|
-
if (JSON.stringify(config) !== lastConfig || configFile !== lastConfigFile) {
|
|
53
|
-
lastConfig = JSON.stringify(config);
|
|
54
|
-
lastConfigFile = configFile;
|
|
55
|
-
writeConfig(configFile, config);
|
|
56
|
-
}
|
|
57
|
-
writeFilePath(filePath);
|
|
58
|
-
writeString(fileText);
|
|
59
|
-
const retv = TSPlugin.format();
|
|
60
|
-
switch (retv) {
|
|
61
|
-
case 0: // no change
|
|
62
|
-
return undefined;
|
|
63
|
-
case 1: // change
|
|
64
|
-
return readFormattedText();
|
|
65
|
-
case 2: // error
|
|
66
|
-
debug("FAILED TO FORMAT: %s", readErrorText());
|
|
67
|
-
return undefined;
|
|
68
|
-
default:
|
|
69
|
-
debug("FAILED TO FORMAT: Unknown response code (%d)", retv);
|
|
70
|
-
return undefined;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.format = format;
|
|
74
|
-
function isConfigAllowedType(value) {
|
|
75
|
-
return ["string", "number", "boolean"].includes(typeof value);
|
|
76
|
-
}
|
|
77
|
-
function extractConfig(config, toConfig) {
|
|
78
|
-
for (const [key, value] of Object.entries(config)) {
|
|
79
|
-
if (isConfigAllowedType(value)) {
|
|
80
|
-
toConfig[key] = value;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Write the config to the plugin.
|
|
86
|
-
* @param config The config object.
|
|
87
|
-
*/
|
|
88
|
-
function writeConfig(configFile, config) {
|
|
89
|
-
TSPlugin.reset_config();
|
|
90
|
-
// The setting values must be strings.
|
|
91
|
-
const globalConfig = {};
|
|
92
|
-
const pluginConfig = {};
|
|
93
|
-
if ((configFile === null || configFile === void 0 ? void 0 : configFile.length) && fs_1.default.existsSync(configFile)) {
|
|
94
|
-
const configFileContent = fs_1.default.readFileSync(configFile, { encoding: "utf-8" });
|
|
95
|
-
const configFileJson = JSONC.parse(configFileContent);
|
|
96
|
-
extractConfig(configFileJson, globalConfig);
|
|
97
|
-
const typescriptConfig = configFileJson.typescript;
|
|
98
|
-
if (typeof typescriptConfig === "object") {
|
|
99
|
-
extractConfig(typescriptConfig, pluginConfig);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
extractConfig(config, pluginConfig);
|
|
103
|
-
writeString(JSON.stringify(globalConfig));
|
|
104
|
-
TSPlugin.set_global_config();
|
|
105
|
-
writeString(JSON.stringify(pluginConfig));
|
|
106
|
-
TSPlugin.set_plugin_config();
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Write the file path to the plugin.
|
|
110
|
-
* @param value The path to the file.
|
|
111
|
-
*/
|
|
112
|
-
function writeFilePath(value) {
|
|
113
|
-
writeString(value);
|
|
114
|
-
TSPlugin.set_file_path();
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Read the text that the last `TSPlugin.format()` call formatted.
|
|
118
|
-
* @returns The formatted text.
|
|
119
|
-
*/
|
|
120
|
-
function readFormattedText() {
|
|
121
|
-
return readString(TSPlugin.get_formatted_text());
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Read the error message that the last `TSPlugin.format()` call caused.
|
|
125
|
-
* @returns The error message.
|
|
126
|
-
*/
|
|
127
|
-
function readErrorText() {
|
|
128
|
-
return readString(TSPlugin.get_error_text());
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Write a string to the plugin.
|
|
132
|
-
* @param text The text to write.
|
|
133
|
-
*/
|
|
134
|
-
function writeString(text) {
|
|
135
|
-
const buffer = Buffer.from(text, "utf8");
|
|
136
|
-
const length = buffer.byteLength;
|
|
137
|
-
TSPlugin.clear_shared_bytes(length);
|
|
138
|
-
let index = 0;
|
|
139
|
-
while (index < length) {
|
|
140
|
-
const writeCount = Math.min(length - index, BufferSize);
|
|
141
|
-
buffer.copy(new Uint8Array(TSPlugin
|
|
142
|
-
.memory
|
|
143
|
-
.buffer, TSPlugin.get_wasm_memory_buffer(), writeCount), 0, index, index + writeCount);
|
|
144
|
-
TSPlugin.add_to_shared_bytes_from_buffer(writeCount);
|
|
145
|
-
index += writeCount;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Read a text from the plugin.
|
|
150
|
-
* @param length The byte length of the string.
|
|
151
|
-
* @returns The read text.
|
|
152
|
-
*/
|
|
153
|
-
function readString(length) {
|
|
154
|
-
const buffer = Buffer.allocUnsafe(length);
|
|
155
|
-
let index = 0;
|
|
156
|
-
while (index < length) {
|
|
157
|
-
const readCount = Math.min(length - index, BufferSize);
|
|
158
|
-
TSPlugin.set_buffer_with_shared_bytes(index, readCount);
|
|
159
|
-
buffer.set(new Uint8Array(TSPlugin
|
|
160
|
-
.memory
|
|
161
|
-
.buffer, TSPlugin.get_wasm_memory_buffer(), readCount), index);
|
|
162
|
-
index += readCount;
|
|
163
|
-
}
|
|
164
|
-
return buffer.toString("utf8");
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=typescript.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../../lib/dprint/typescript.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAuC;AACvC,kDAA+B;AAC/B,4CAAmB;AACnB,oDAAqC;AAErC,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,sBAAsB,CAAC,CAAA;AAOjD,mCAAmC;AACnC,MAAM,YAAY,GAAG,oBAAM,CAAC,OAAO,EAAE,CAAA;AACrC,MAAM,cAAc,GAAG,IAAI,WAAW,CAAC,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