Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Aug 25, 2024
1 parent 5f894e5 commit 07c8e12
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion lib/codenarc-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import Debug from 'debug';
const debug = Debug("npm-groovy-lint");
import * as commondir from "commondir";
import * as fs from "fs-extra";
import fs from 'fs-extra'
import * as os from "os";
import * as path from "path";
import { getConfigFileName } from "./config.js";import { collectDisabledBlocks, isFilteredError } from "./filter.js";
Expand Down
16 changes: 8 additions & 8 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import Debug from 'debug';
const debug = Debug("npm-groovy-lint");
import * as fs from "fs-extra";
import fs from 'fs-extra'
import importFresh from "import-fresh";
import * as path from "path";
import * as stripComments from "strip-json-comments";
import stripJsonComments from "strip-json-comments";
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -120,7 +120,7 @@ async function getConfigFileName(startPathOrFile, sourcefilepath, fileNames = co
// Find one of the config file formats are the root of the linted file (if source is sent with sourcefilepath)
if ([".", process.cwd()].includes(startPathOrFile) && sourcefilepath) {
try {
const stat = await fse.lstat(sourcefilepath);
const stat = await fs.lstat(sourcefilepath);
const dir = stat.isDirectory() ? sourcefilepath : path.parse(sourcefilepath).dir;
configFilePath = await findConfigInPath(dir, fileNames);
} catch (e) {
Expand All @@ -130,7 +130,7 @@ async function getConfigFileName(startPathOrFile, sourcefilepath, fileNames = co
// Find one of the config file formats at the root of the project or at upper directory levels
if (configFilePath == null) {
try {
const stat = await fse.lstat(startPathOrFile);
const stat = await fs.lstat(startPathOrFile);
const dir = stat.isDirectory ? startPathOrFile : path.parse(startPathOrFile).dir;
configFilePath = await findConfigInPath(dir, fileNames);
} catch (e) {
Expand All @@ -157,7 +157,7 @@ async function getConfigFileName(startPathOrFile, sourcefilepath, fileNames = co
async function findConfigInPath(directoryPath, configFilenamesIn) {
for (const filename of configFilenamesIn) {
const filePath = path.join(directoryPath, filename);
if (await fse.exists(filePath)) {
if (await fs.exists(filePath)) {
if (filename === "package.json") {
try {
await loadPackageJSONConfigFile(filePath);
Expand Down Expand Up @@ -221,8 +221,8 @@ async function loadJSConfigFile(filePath) {
// JSON format
async function loadJSONConfigFile(filePath) {
try {
const fileContent = await readFile(filePath);
return JSON.parse(stripComments(fileContent));
const fileContent = await fs.readFile(filePath);
return JSON.parse(stripJsonComments(fileContent.toString()));
} catch (e) {
debug(`Error reading JSON file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
Expand All @@ -238,7 +238,7 @@ async function loadJSONConfigFile(filePath) {
// YAML format
async function loadYAMLConfigFile(filePath) {
// lazy load YAML to improve performance when not used
const yaml = require("js-yaml");
const yaml = await import("js-yaml");

try {
// empty YAML file can be null, so always use
Expand Down
4 changes: 2 additions & 2 deletions lib/groovy-lint-fix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Imports
import * as fse from "fs-extra";
import fs from 'fs-extra'
import * as cliProgress from "cli-progress";
import Debug from 'debug';
const debug = Debug("npm-groovy-lint");
Expand Down Expand Up @@ -218,7 +218,7 @@ export class NpmGroovyLintFix {
this.updatedLintResult.files[fileNm].updatedSource = newSources;
// Write new file content if it has been updated
if (this.options.save && fixedInFileNb > 0) {
fse.writeFileSync(fileNm, newSources);
fs.writeFileSync(fileNm, newSources);
}
}),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/groovy-lint-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ str = "lelamanul"
*/


import fse from 'fs-extra';
const { readdirSync } = fse;
import fs from 'fs-extra';
const { readdirSync } = fs;
import * as path from 'path';
import { fileURLToPath } from 'url';

Expand Down
2 changes: 1 addition & 1 deletion lib/groovy-lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Debug from 'debug';
const debug = Debug("npm-groovy-lint");
const trace = Debug("npm-groovy-lint-trace");
import * as fs from "fs-extra";
import fs from 'fs-extra'
import * as os from "os";
import * as path from "path";
import { performance } from 'node:perf_hooks';
Expand Down
8 changes: 4 additions & 4 deletions lib/output.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Output management
import * as c from "ansi-colors";
import * as fse from "fs-extra";
import fs from 'fs-extra'
import { SarifBuilder, SarifRunBuilder, SarifResultBuilder, SarifRuleBuilder } from "node-sarif-builder";
import * as path from "path";
import { isErrorInLogLevelScope, getNpmGroovyLintVersion } from "./utils.js";
Expand Down Expand Up @@ -188,7 +188,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
// Output text log in file
if (output.endsWith(".txt")) {
const fullFileContent = outputString;
fse.writeFileSync(output, fullFileContent);
fs.writeFileSync(output, fullFileContent);
console.table(summaryTable, fixer ? ["Severity", "Total found", "Total fixed", "Total remaining"] : ["Severity", "Total found"]);
const absolutePath = path.resolve(".", output);
console.info("GroovyLint: Logged results in file " + absolutePath);
Expand All @@ -203,7 +203,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
// Output log
if (output.endsWith(".json")) {
const fullFileContent = JSON.stringify(lintResult, null, 2);
fse.writeFileSync(output, fullFileContent);
fs.writeFileSync(output, fullFileContent);
const absolutePath = path.resolve(".", output);
console.info("GroovyLint: Logged results in file " + absolutePath);
} else {
Expand All @@ -216,7 +216,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
const sarifJsonString = buildSarifResult(lintResult);
// SARIF file
if (output.endsWith(".sarif")) {
fse.writeFileSync(output, sarifJsonString);
fs.writeFileSync(output, sarifJsonString);
const absolutePath = path.resolve(".", output);
outputString = "GroovyLint: Logged SARIF results in file " + absolutePath;
console.info(outputString);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Debug from 'debug';
const debug = Debug("npm-groovy-lint");
const trace = Debug("npm-groovy-lint-trace");
import * as decodeHtml from "decode-html";
import * as fs from "fs-extra";
import fs from 'fs-extra'
import * as os from "os";
import * as path from "path";
import { fileURLToPath } from 'url';
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-config-all.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as fs from "fs-extra";
import fs from 'fs-extra'
const { getNpmGroovyLintRules } = require("../lib/groovy-lint-rules.js");
// Build Json containing all CodeNarc rules
(async () => {
Expand Down
2 changes: 1 addition & 1 deletion test/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
const NpmGroovyLint = require("../lib/groovy-lint.js");
let assert = require("assert");
import * as fs from "fs-extra";
import fs from 'fs-extra'
const { SAMPLE_FILE_SMALL_PATH } = require("./helpers/common");

describe("Errors", function() {
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/common.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
let assert = require("assert");
import * as os from "os";
import * as fse from "fs-extra";
import fs from 'fs-extra'
const jsdiff = require("diff");

const NPM_GROOVY_LINT = "npm-groovy-lint ";
Expand Down Expand Up @@ -44,8 +44,8 @@ async function copyFilesInTmpDir() {
? "./tmptest"
: os.tmpdir(); // Windows / other
const tmpDir = rootTmpDir + "/" + ("tmpGroovyLintTest_" + Math.random()).replace(".", "");
await fse.ensureDir(tmpDir, { mode: "0777" });
await fse.copy("./lib/example", tmpDir);
await fs.ensureDir(tmpDir, { mode: "0777" });
await fs.copy("./lib/example", tmpDir);
console.info("GroovyLint: Copied ./lib/example into " + tmpDir);
return tmpDir;
}
Expand Down
2 changes: 1 addition & 1 deletion test/lint-api.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
const NpmGroovyLint = require("../lib/groovy-lint.js");
let assert = require("assert");
import * as fs from "fs-extra";
import fs from 'fs-extra'
import * as path from "path";
const {
beforeEachTestCase,
Expand Down
2 changes: 1 addition & 1 deletion test/lint-build-fix.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
let assert = require("assert");
const util = require("util");
import * as fs from "fs-extra";
import fs from 'fs-extra'
const rimraf = require("rimraf");
const childProcess = require("child_process");
const exec = util.promisify(childProcess.exec);
Expand Down
2 changes: 1 addition & 1 deletion test/lint-build-format.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
let assert = require("assert");
const util = require("util");
import * as fs from "fs-extra";
import fs from 'fs-extra'
const rimraf = require("rimraf");
const childProcess = require("child_process");
const exec = util.promisify(childProcess.exec);
Expand Down
10 changes: 5 additions & 5 deletions test/lint-build.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
const util = require("util");
let assert = require("assert");
import * as fse from "fs-extra";
import fs from 'fs-extra'
import * as path from "path";
const childProcess = require("child_process");
const exec = util.promisify(childProcess.exec);
Expand Down Expand Up @@ -145,8 +145,8 @@ describe("Lint with executable", () => {
`-report="html:${reportFileName}"`
];
await exec(NPM_GROOVY_LINT + params.join(" "));
assert(fse.existsSync(reportFileName), "html CodeNarc report has been generated at " + reportFileName);
fse.removeSync(reportFileName);
assert(fs.existsSync(reportFileName), "html CodeNarc report has been generated at " + reportFileName);
fs.removeSync(reportFileName);
});

it("(EXE:file) should generate codenarc XML file report", async function() {
Expand All @@ -159,8 +159,8 @@ describe("Lint with executable", () => {
`-report="xml:${reportFileName}"`
];
await exec(NPM_GROOVY_LINT + params.join(" "));
assert(fse.existsSync(reportFileName), "xml CodeNarc report has been generated at " + reportFileName);
fse.removeSync(reportFileName);
assert(fs.existsSync(reportFileName), "xml CodeNarc report has been generated at " + reportFileName);
fs.removeSync(reportFileName);
});

it("(EXE:file) should run on a Jenkinsfile", async function() {
Expand Down
2 changes: 1 addition & 1 deletion test/lint-fix.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
const NpmGroovyLint = require("../lib/groovy-lint.js");
let assert = require("assert");
import * as fs from "fs-extra";
import fs from 'fs-extra'
const rimraf = require("rimraf");
const {
beforeEachTestCase,
Expand Down
2 changes: 1 addition & 1 deletion test/lint-format.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node
const NpmGroovyLint = require("../lib/groovy-lint.js");
let assert = require("assert");
import * as fs from "fs-extra";
import fs from 'fs-extra'
const { normalizeNewLines } = require("../lib/utils.js");
const rimraf = require("rimraf");
const {
Expand Down
16 changes: 8 additions & 8 deletions test/miscellaneous.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const NpmGroovyLint = require("../lib/groovy-lint.js");
let assert = require("assert");
const childProcess = require("child_process");
import * as fse from "fs-extra";
import fs from 'fs-extra'
import * as os from "os";
import * as path from "path";
const util = require("util")
Expand Down Expand Up @@ -37,8 +37,8 @@ describe("Miscellaneous", function() {

it("(API:source) load config using specific file name", async function() {
const customConfigFilePath = process.platform.includes("linux") ? "~/.groovylintrc-custom.json" : os.tmpdir() + "\\.groovylintrc-custom.json";
await fse.ensureDir("~/", { mode: "0777" });
await fse.copy("./lib/example/.groovylintrc-custom.json", customConfigFilePath);
await fs.ensureDir("~/", { mode: "0777" });
await fs.copy("./lib/example/.groovylintrc-custom.json", customConfigFilePath);
const npmGroovyLintConfig = {
config: customConfigFilePath,
path: "./lib/example/",
Expand All @@ -48,7 +48,7 @@ describe("Miscellaneous", function() {
verbose: true
};
const linter = await new NpmGroovyLint(npmGroovyLintConfig, {}).run();
await fse.remove(customConfigFilePath);
await fs.remove(customConfigFilePath);
const rules = linter.options.rules || {};
assert(rules["CompileStatic"] == "off", "CompileStatic is off");
assert(rules["CouldBeElvis"] == "off", "CouldBeElvis is off");
Expand Down Expand Up @@ -305,10 +305,10 @@ describe("Miscellaneous", function() {
beforeEachTestCase(); // Call manually as beforeEach only works from the CLI.

const logFile = "npm-groovy-lint.log";
let logFileExist = fse.existsSync(logFile);
let logFileExist = fs.existsSync(logFile);
if (logFileExist) {
// Remove old log file.
await fse.remove(logFile);
await fs.remove(logFile);
}

const npmGroovyLintConfig = {
Expand All @@ -323,7 +323,7 @@ describe("Miscellaneous", function() {
assert(linter.status === 1, `Linter status is 0 (${linter.status} returned)`);
checkCodeNarcCallsCounter(1);

logFileExist = fse.existsSync(logFile)
logFileExist = fs.existsSync(logFile)
assert(!logFileExist, "npm-groovy-lint.log has been created");

// Enable log file.
Expand All @@ -333,7 +333,7 @@ describe("Miscellaneous", function() {
assert(linter.status === 1, `Linter status is 1 (${linter.status} returned)`);
checkCodeNarcCallsCounter(2);

logFileExist = fse.existsSync(logFile);
logFileExist = fs.existsSync(logFile);
assert(logFileExist, "npm-groovy-lint.log has not been created");
});
});
Expand Down

0 comments on commit 07c8e12

Please sign in to comment.