npm-groovy-lint
Advanced tools
Comparing version 10.0.1 to 10.0.2
@@ -5,2 +5,7 @@ # Changelog | ||
## [10.0.2] 2022-08-15 | ||
- Fix error when absolute files sent as positional arguments on a linux system ([#232](https://github.com/nvuillam/npm-groovy-lint/issues/232)) | ||
- Improve performances by calculating the longest command directory to send as base path to CodeNarc | ||
## [10.0.1] 2022-08-14 | ||
@@ -7,0 +12,0 @@ |
@@ -5,2 +5,3 @@ // Shared functions | ||
const debug = require("debug")("npm-groovy-lint"); | ||
const commondir = require("commondir"); | ||
const fs = require("fs-extra"); | ||
@@ -59,4 +60,7 @@ const os = require("os"); | ||
const baseBefore = (cnPath !== "." && cnPath.startsWith("/")) || cnPath.includes(":/") || cnPath.includes(":\\") ? "" : process.cwd() + "/"; | ||
result.codeNarcBaseDir = cnPath !== "." ? baseBefore + cnPath.replace(/^"(.*)"$/, "$1") : process.cwd(); | ||
result.codeNarcBaseDir = path.resolve(result.codeNarcBaseDir); | ||
const codeNarcBaseDir = positionalArgs.length > 0 ? | ||
(await getCodeNarcBaseDirFromFiles(positionalArgs)) : | ||
cnPath !== "." ? baseBefore + cnPath.replace(/^"(.*)"$/, "$1") : | ||
process.cwd(); | ||
result.codeNarcBaseDir = path.resolve(codeNarcBaseDir); | ||
result.codenarcArgs.push(`-basedir=${result.codeNarcBaseDir}`); | ||
@@ -95,13 +99,14 @@ | ||
} | ||
// Absolute or cwd - relative path file | ||
if (fs.existsSync(finalPattern)) { | ||
// Relative with codeNarcBaseDir | ||
else if (fs.existsSync(path.join(result.codeNarcBaseDir, finalPattern))) { | ||
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/"); | ||
const relativePath = path.relative(process.cwd(), path.resolve(finalPattern)).replace(/\\/gu, "/"); | ||
fileList.push(absolutePath); | ||
const relativePath = finalPattern.replace(/\\/gu, "/"); | ||
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/"); | ||
} | ||
// Relative with codeNardBaseDir | ||
else if (fs.existsSync(path.join(result.codeNarcBaseDir, finalPattern))) { | ||
const relativePath = path.relative(process.cwd(), path.join(result.codeNarcBaseDir, finalPattern)).replace(/\\/gu, "/"); | ||
fileList.push(relativePath); | ||
// Absolute or cwd - relative path file | ||
else if (fs.existsSync(finalPattern)) { | ||
const absolutePath = path.resolve(finalPattern).replace(/\\/gu, "/"); | ||
fileList.push(absolutePath); | ||
const relativePath = path.relative(result.codeNarcBaseDir, path.resolve(finalPattern)).replace(/\\/gu, "/"); | ||
finalPattern = "**/" + path.normalize(relativePath.replace(/[/\\]$/u, "")).replace(/\\/gu, "/"); | ||
@@ -180,2 +185,21 @@ } | ||
// Calculate longest base dir by analyzing the list of files | ||
async function getCodeNarcBaseDirFromFiles(positionalArgs) { | ||
// All arguments are not files | ||
if (!positionalArgs.every(fileOrDirOrPattern => fs.existsSync(fileOrDirOrPattern) || directoryExists(fileOrDirOrPattern))) { | ||
return process.cwd() | ||
} | ||
const folders = positionalArgs.map((fileOrDir) => { | ||
// Dir | ||
if (directoryExists(fileOrDir)) { | ||
return path.resolve(fileOrDir); | ||
} | ||
// File dir | ||
const fileAbsolute = path.resolve(fileOrDir); | ||
return path.dirname(fileAbsolute); | ||
}); | ||
const baseDirFromFiles = commondir(folders); | ||
return baseDirFromFiles | ||
} | ||
// Parse XML result file as js object | ||
@@ -182,0 +206,0 @@ async function parseCodeNarcResult(options, codeNarcBaseDir, codeNarcJsonResult, tmpGroovyFileName, parseErrors) { |
{ | ||
"name": "npm-groovy-lint", | ||
"version": "10.0.1", | ||
"version": "10.0.2", | ||
"description": "Lint, format and auto-fix your Groovy / Jenkinsfile / Gradle files", | ||
@@ -52,2 +52,3 @@ "main": "index.js", | ||
"cli-progress": "^3.10.0", | ||
"commondir": "^1.0.1", | ||
"debug": "^4.1.1", | ||
@@ -54,0 +55,0 @@ "decode-html": "^2.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16991053
7255
21
+ Addedcommondir@^1.0.1
+ Addedcommondir@1.0.1(transitive)