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