npm-groovy-lint 10.0.1 → 10.0.2
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.
- package/CHANGELOG.md +5 -0
- package/lib/codenarc-factory.js +33 -9
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
## UNRELEASED
|
|
4
4
|
|
|
5
|
+
## [10.0.2] 2022-08-15
|
|
6
|
+
|
|
7
|
+
- Fix error when absolute files sent as positional arguments on a linux system ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232))
|
|
8
|
+
- Improve performances by calculating the longest command directory to send as base path to CodeNarc
|
|
9
|
+
|
|
5
10
|
## [10.0.1] 2022-08-14
|
|
6
11
|
|
|
7
12
|
- Fix error when files sent as positional arguments ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232))
|
package/lib/codenarc-factory.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
const debug = require("debug")("npm-groovy-lint");
|
|
5
|
+
const commondir = require("commondir");
|
|
5
6
|
const fs = require("fs-extra");
|
|
6
7
|
const os = require("os");
|
|
7
8
|
const path = require("path");
|
|
@@ -55,8 +56,11 @@ async function prepareCodeNarcCall(options) {
|
|
|
55
56
|
|
|
56
57
|
// Define base directory
|
|
57
58
|
const baseBefore = (cnPath !== "." && cnPath.startsWith("/")) || cnPath.includes(":/") || cnPath.includes(":\\") ? "" : process.cwd() + "/";
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
const codeNarcBaseDir = positionalArgs.length > 0 ?
|
|
60
|
+
(await getCodeNarcBaseDirFromFiles(positionalArgs)) :
|
|
61
|
+
cnPath !== "." ? baseBefore + cnPath.replace(/^"(.*)"$/, "$1") :
|
|
62
|
+
process.cwd();
|
|
63
|
+
result.codeNarcBaseDir = path.resolve(codeNarcBaseDir);
|
|
60
64
|
result.codenarcArgs.push(`-basedir=${result.codeNarcBaseDir}`);
|
|
61
65
|
|
|
62
66
|
// Create ruleSet groovy file if necessary
|
|
@@ -90,17 +94,18 @@ async function prepareCodeNarcCall(options) {
|
|
|
90
94
|
if (directoryExists(resolvedPath)) {
|
|
91
95
|
finalPattern = "**/" + path.normalize(pathname.replace(/[/\\]$/u, "")).replace(/\\/gu, "/") + filePatterns;
|
|
92
96
|
}
|
|
93
|
-
//
|
|
94
|
-
if (fs.existsSync(finalPattern)) {
|
|
97
|
+
// Relative with codeNarcBaseDir
|
|
98
|
+
else if (fs.existsSync(path.join(result.codeNarcBaseDir, finalPattern))) {
|
|
95
99
|
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/");
|
|
96
|
-
const relativePath = path.relative(process.cwd(), path.resolve(finalPattern)).replace(/\\/gu, "/");
|
|
97
100
|
fileList.push(absolutePath);
|
|
101
|
+
const relativePath = finalPattern.replace(/\\/gu, "/");
|
|
98
102
|
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
|
|
99
103
|
}
|
|
100
|
-
//
|
|
101
|
-
else if (fs.existsSync(
|
|
102
|
-
const
|
|
103
|
-
fileList.push(
|
|
104
|
+
// Absolute or cwd - relative path file
|
|
105
|
+
else if (fs.existsSync(finalPattern)) {
|
|
106
|
+
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/");
|
|
107
|
+
fileList.push(absolutePath);
|
|
108
|
+
const relativePath = path.relative(result.codeNarcBaseDir, path.resolve(finalPattern)).replace(/\\/gu, "/");
|
|
104
109
|
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/");
|
|
105
110
|
}
|
|
106
111
|
// Directory or ant pattern
|
|
@@ -174,6 +179,25 @@ async function prepareCodeNarcCall(options) {
|
|
|
174
179
|
return result;
|
|
175
180
|
}
|
|
176
181
|
|
|
182
|
+
// Calculate longest base dir by analyzing the list of files
|
|
183
|
+
async function getCodeNarcBaseDirFromFiles(positionalArgs) {
|
|
184
|
+
// All arguments are not files
|
|
185
|
+
if (!positionalArgs.every(fileOrDirOrPattern => fs.existsSync(fileOrDirOrPattern) || directoryExists(fileOrDirOrPattern))) {
|
|
186
|
+
return process.cwd()
|
|
187
|
+
}
|
|
188
|
+
const folders = positionalArgs.map((fileOrDir) => {
|
|
189
|
+
// Dir
|
|
190
|
+
if (directoryExists(fileOrDir)) {
|
|
191
|
+
return path.resolve(fileOrDir);
|
|
192
|
+
}
|
|
193
|
+
// File dir
|
|
194
|
+
const fileAbsolute = path.resolve(fileOrDir);
|
|
195
|
+
return path.dirname(fileAbsolute);
|
|
196
|
+
});
|
|
197
|
+
const baseDirFromFiles = commondir(folders);
|
|
198
|
+
return baseDirFromFiles
|
|
199
|
+
}
|
|
200
|
+
|
|
177
201
|
// Parse XML result file as js object
|
|
178
202
|
async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult, tmpGroovyFileName, parseErrors) {
|
|
179
203
|
if (!codeNarcJsonResult || !codeNarcJsonResult.codeNarc || !codeNarcJsonResult.packages) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-groovy-lint",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2",
|
|
4
4
|
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"axios": "^0.21.1",
|
|
50
50
|
"chalk": "^4.1.2",
|
|
51
51
|
"cli-progress": "^3.10.0",
|
|
52
|
+
"commondir": "^1.0.1",
|
|
52
53
|
"debug": "^4.1.1",
|
|
53
54
|
"decode-html": "^2.0.0",
|
|
54
55
|
"find-java-home": "^1.1.0",
|