-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
37 lines (37 loc) · 976 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Beautifier, Language, BeautifierBeautifyData, DependencyType } from "unibeautify";
import * as readPkgUp from "read-pkg-up";
import options from "./options";
const CLIEngine = require("eslint").CLIEngine;
const { pkg } = readPkgUp.sync({ cwd: __dirname });
export const beautifier: Beautifier = {
name: "ESLint",
package: pkg,
dependencies: [
{
type: DependencyType.Node,
name: "ESLint",
package: "eslint",
}
],
options: {
JavaScript: options.JavaScript,
},
beautify(data: BeautifierBeautifyData) {
return new Promise<string>((resolve, reject) => {
const cli = new CLIEngine({
fix: true,
parserOptions: {
ecmaVersion: 6,
},
rules: data.options,
});
const text = cli.executeOnText(data.text).results[0].output;
if (text) {
return resolve(text);
} else {
return resolve(data.text);
}
});
},
};
export default beautifier;