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