@pi-r/eslint 0.7.2 → 0.7.4

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.
Files changed (3) hide show
  1. package/README.md +6 -6
  2. package/index.js +43 -15
  3. package/package.json +27 -26
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
- ### @pi-r/eslint
2
-
3
- https://e-mc.readthedocs.io/en/latest/document/plugins/built-in.html
4
-
5
- ### LICENSE
6
-
1
+ ### @pi-r/eslint
2
+
3
+ https://e-mc.readthedocs.io/en/latest/document/plugins/built-in.html
4
+
5
+ ### LICENSE
6
+
7
7
  MIT
package/index.js CHANGED
@@ -1,25 +1,53 @@
1
1
  "use strict";
2
+ const path = require("path");
3
+ const Types = require("@e-mc/types");
2
4
  const Document = require("@e-mc/document");
3
5
  module.exports = async function transform(context, value, options) {
4
6
  context = options.upgrade(context, __dirname);
5
7
  const { pathname, filename } = options;
6
8
  const timeStamp = Date.now();
7
- const report = (await new context.ESLint(options.toBaseConfig()).lintText(value))[0];
8
- if (report?.messages.length) {
9
- const fatal = report.messages.filter(item => item.fatal).map(item => item.message);
10
- if (fatal.length) {
11
- throw new Error(fatal.join('\n\n'));
9
+ const baseConfig = options.toBaseConfig();
10
+ const instance = new context.ESLint(baseConfig);
11
+ const result = await instance.lintText(value);
12
+ if (result.length) {
13
+ if (baseConfig.fix) {
14
+ await context.ESLint.outputFixes(result);
15
+ }
16
+ const report = result[0];
17
+ if (report) {
18
+ if (report.messages.length) {
19
+ const fatal = report.messages.filter(item => item.fatal);
20
+ if (fatal.length) {
21
+ throw new Error(fatal.map(item => item.message).join('\n\n'));
22
+ }
23
+ const attr = Document.hasLogType(options.logType.STDOUT) ? 'logQueued' : 'logAppend';
24
+ if (process.env.ESLINT_FORMATTER_NAME) {
25
+ const formatter = await instance.loadFormatter(process.env.ESLINT_FORMATTER_NAME);
26
+ const output = await formatter.format(result);
27
+ options.out[attr] = [{
28
+ type: Types.STATUS_TYPE.INFO,
29
+ value: output.replace('<text>', pathname && filename ? path.join(pathname, filename) : 'File location: Unknown'),
30
+ timeStamp, duration: Date.now() - timeStamp,
31
+ from: 'eslint', source: process.env.ESLINT_FORMATTER_NAME
32
+ }];
33
+ }
34
+ else {
35
+ options.out[attr] = Document.generateLintTable(report.messages.map(item => ({
36
+ ruleId: item.ruleId || 'unknown',
37
+ line: item.line,
38
+ column: item.column,
39
+ message: item.message,
40
+ severity: item.severity
41
+ })), { leadingText: 'eslint', pathname, filename, errorCount: report.errorCount, warningCount: report.warningCount, trailingText: 'https://eslint.org/docs/latest/rules', timeStamp });
42
+ }
43
+ }
44
+ else {
45
+ options.out.messageAppend = ` -> valid(${!report || report.errorCount || report.warningCount ? 'NO' : 'YES'})`;
46
+ }
47
+ if (baseConfig.fix && report.output) {
48
+ return report.output;
49
+ }
12
50
  }
13
- options.out[Document.hasLogType(options.logType.STDOUT) ? 'logQueued' : 'logAppend'] = Document.generateLintTable(report.messages.map(item => ({
14
- ruleId: item.ruleId || 'unknown',
15
- line: item.line,
16
- column: item.column,
17
- message: item.message,
18
- severity: item.severity
19
- })), { leadingText: 'eslint', pathname, filename, errorCount: report.errorCount, warningCount: report.warningCount, trailingText: 'https://eslint.org/docs/rules', timeStamp });
20
- }
21
- else {
22
- options.out.messageAppend = ` -> valid(${!report || report.errorCount || report.warningCount ? 'NO' : 'YES'})`;
23
51
  }
24
52
  return value;
25
53
  };
package/package.json CHANGED
@@ -1,26 +1,27 @@
1
- {
2
- "name": "@pi-r/eslint",
3
- "version": "0.7.2",
4
- "description": "eslint transform function for E-mc.",
5
- "main": "index.js",
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/anpham6/pi-r.git",
12
- "directory": "src/documemt/eslint"
13
- },
14
- "keywords": [
15
- "squared",
16
- "e-mc",
17
- "squared-functions"
18
- ],
19
- "author": "An Pham <anpham6@gmail.com>",
20
- "license": "MIT",
21
- "homepage": "https://github.com/anpham6/pi-r#readme",
22
- "dependencies": {
23
- "@e-mc/document": "^0.9.4",
24
- "eslint": "^8.57.0"
25
- }
26
- }
1
+ {
2
+ "name": "@pi-r/eslint",
3
+ "version": "0.7.4",
4
+ "description": "eslint transform function for E-mc.",
5
+ "main": "index.js",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/anpham6/pi-r.git",
12
+ "directory": "src/documemt/eslint"
13
+ },
14
+ "keywords": [
15
+ "squared",
16
+ "e-mc",
17
+ "squared-functions"
18
+ ],
19
+ "author": "An Pham <anpham6@gmail.com>",
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/anpham6/pi-r#readme",
22
+ "dependencies": {
23
+ "@e-mc/document": "^0.9.12",
24
+ "@eslint/js": "^8.57.0",
25
+ "eslint": "^8.57.0"
26
+ }
27
+ }