@pi-r/eslint 0.7.3 → 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 +12 -10
  3. package/package.json +6 -6
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
@@ -2,23 +2,25 @@
2
2
  const path = require("path");
3
3
  const Types = require("@e-mc/types");
4
4
  const Document = require("@e-mc/document");
5
+ const { loadESLint } = require('eslint');
5
6
  module.exports = async function transform(context, value, options) {
6
7
  context = options.upgrade(context, __dirname);
7
8
  const { pathname, filename } = options;
8
9
  const timeStamp = Date.now();
9
10
  const baseConfig = options.toBaseConfig();
10
- const instance = new context.ESLint(baseConfig);
11
- const result = await instance.lintText(value);
12
- if (result.length) {
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) {
13
15
  if (baseConfig.fix) {
14
- await context.ESLint.outputFixes(result);
16
+ await ESLint.outputFixes(result);
15
17
  }
16
18
  const report = result[0];
17
19
  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'));
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'));
22
24
  }
23
25
  const attr = Document.hasLogType(options.logType.STDOUT) ? 'logQueued' : 'logAppend';
24
26
  if (process.env.ESLINT_FORMATTER_NAME) {
@@ -26,7 +28,7 @@ module.exports = async function transform(context, value, options) {
26
28
  const output = await formatter.format(result);
27
29
  options.out[attr] = [{
28
30
  type: Types.STATUS_TYPE.INFO,
29
- value: output.replace('<text>', pathname && filename ? path.join(pathname, filename) : 'File location: Unknown'),
31
+ value: output.replace('<text>', 'File location: Unknown'),
30
32
  timeStamp, duration: Date.now() - timeStamp,
31
33
  from: 'eslint', source: process.env.ESLINT_FORMATTER_NAME
32
34
  }];
@@ -38,7 +40,7 @@ module.exports = async function transform(context, value, options) {
38
40
  column: item.column,
39
41
  message: item.message,
40
42
  severity: item.severity
41
- })), { leadingText: 'eslint', pathname, filename, errorCount: report.errorCount, warningCount: report.warningCount, trailingText: 'https://eslint.org/docs/latest/rules', timeStamp });
43
+ })), { leadingText: 'eslint', pathname, filename, errorCount: [report.errorCount, report.fixableErrorCount], warningCount: [report.warningCount, report.fixableWarningCount], trailingText: 'https://eslint.org/docs/latest/rules', timeStamp });
42
44
  }
43
45
  }
44
46
  else {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pi-r/eslint",
3
- "version": "0.7.3",
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,8 +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.6",
24
- "@eslint/js": "^8.57.0",
25
- "eslint": "^8.57.0"
23
+ "@e-mc/document": "^0.10.0",
24
+ "@eslint/js": "^9.8.0",
25
+ "eslint": "^9.8.0"
26
26
  }
27
27
  }