Skip to content

Commit

Permalink
More ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Aug 25, 2024
1 parent 07c8e12 commit f294f72
Show file tree
Hide file tree
Showing 82 changed files with 154 additions and 156 deletions.
14 changes: 6 additions & 8 deletions lib/codenarc-caller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JavaCaller } from "java-caller";
import { optionsDefinition } from "./options.js";
import { performance } from 'node:perf_hooks';
import * as c from "chalk";
import * as findJavaHome from 'find-java-home';
import * as path from "path";
import { fileURLToPath } from "node:url";

Expand Down Expand Up @@ -238,14 +239,11 @@ export class CodeNarcCaller {
reason =
"It seems node.js has not been found on your computer. Please install a recent node.js: https://nodejs.org/en/download/\nIf node is already installed, make sure your PATH contains node installation folder: https://love2dev.com/blog/node-is-not-recognized-as-an-internal-or-external-command/";
} else {
await new Promise((resolve) => {
require("find-java-home")((err) => {
if (err) {
reason =
"Java is required to run npm-groovy-lint, as CodeNarc is written in Java/Groovy. Please install Java (version 8 minimum) https://www.java.com/download";
}
resolve();
});
await findJavaHome({ allowJre: true }, (err) => {
if (err) {
reason =
"Java is required to run npm-groovy-lint, as CodeNarc is written in Java/Groovy. Please install Java (version 8 minimum) https://www.java.com/download";
}
});
}
return {
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 @@ -170,9 +170,9 @@ export async function getNpmGroovyLintRules(optns = { loadTests: false }) {
const ruleName = file.replace(".js", "");
// Remove require cache if tests must be returned (other calls delete them in the cache)
if (optns && optns.loadTests === true) {
delete require.cache[require.resolve(`${RULES_FOLDER}/${file}`)];
// delete require.cache[require.resolve(`${RULES_FOLDER}/${file}`)]; Not ESM compliant
}
const { rule } = await import(path.join(".", "rules", file));
const { rule } = await import("./rules/" + file);
if (rule.disabled) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/AssignmentInConditional.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Assignment in condition

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BlankLineBeforePackage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Blank line before package

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BlockEndsWithBlankLine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Unused import

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BlockStartsWithBlankLine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Unused import

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BracesForClass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Braces for class

const { moveOpeningBracket, findRangeBetweenStrings } = require("../utils");
import { moveOpeningBracket, findRangeBetweenStrings } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BracesForForLoop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Braces for for loop

const { getVariable, moveOpeningBracket, findRangeBetweenStrings } = require("../utils");
import { getVariable, moveOpeningBracket, findRangeBetweenStrings } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BracesForIfElse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Braces for if else

const { moveOpeningBracket, findRangeBetweenStrings } = require("../utils");
import { moveOpeningBracket, findRangeBetweenStrings } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BracesForMethod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Braces for method

const { moveOpeningBracket, findRangeBetweenStrings, getVariable } = require("../utils");
import { moveOpeningBracket, findRangeBetweenStrings, getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/BracesForTryCatchFinally.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Braces for try catch finally

const { moveOpeningBracket, findRangeBetweenStrings } = require("../utils");
import { moveOpeningBracket, findRangeBetweenStrings } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/CatchException.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Exception type must not be used
const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/ClassEndsWithBlankLine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Unused import

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/ClassStartsWithBlankLine.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Unused import

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/ConsecutiveBlankLines.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Consecutive blank lines

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/DuplicateImport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Duplicate import

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/DuplicateNumberLiteral.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Duplicate number literal

const { getVariableRange } = require("../utils");
import { getVariableRange } from "../utils.js";

const rule = {
variables: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/DuplicateStringLiteral.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Duplicate string literal

const { getVariableRange } = require("../utils");
import { getVariableRange } from "../utils.js";

const rule = {
variables: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/ElseBlockBraces.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Missing else braces
const { containsOtherThan, getStringRangeMultiline, getVariable, isValidCodeLine } = require("../utils");
import { containsOtherThan, getStringRangeMultiline, getVariable, isValidCodeLine } from "../utils";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/IfStatementBraces.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// nvuillam: Fix not always working, especially when embedded missing If statements ...
// let's let people correct that manually for now :)

const { getOutOfBracesStrings, getStringRange, getVariable, isValidCodeLine } = require("../utils");
import { getOutOfBracesStrings, getStringRange, getVariable, isValidCodeLine } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/Indentation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Indentation
// Warning CodeNarc does not like tabs, better replace them by spaces ...

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
triggers: ["IndentationClosingBraces", "IndentationComments"],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/IndentationClosingBraces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { containsExceptInsideString } = require("../utils");
import { containsExceptInsideString } from "../utils.js";

// Indentation closing braces
const rule = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/InsecureRandom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Insecure use of Random
const { addImport, getVariable, getVariableRange } = require("../utils");
import { addImport, getVariable, getVariableRange } from "../utils";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/JavaIoPackageAccess.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// No use of Java.io classes

const { getLastVariableRange } = require("../utils");
import { getLastVariableRange } from "../utils";

//NV: TODO: finalise for when there is several occurrences of the string in the same line
const rule = {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/MethodCount.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Too many methods in a class

const { getVariableRange } = require("../utils");
import { getVariableRange } from "../utils.js";

const rule = {
variables: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/MethodParameterTypeRequired.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Too many methods in a class

const { getVariableRange } = require("../utils");
import { getVariableRange } from "../utils.js";

const rule = {
variables: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/MethodReturnTypeRequired.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Too many methods in a class

const { getVariableRange } = require("../utils");
import { getVariableRange } from "../utils.js";

const rule = {
variables: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/MissingBlankLineAfterImports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Missing blank lines after import

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/MissingBlankLineAfterPackage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Missing blank lines after package

const { getVariable } = require("../utils");
import { getVariable } from "../utils.js";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/NoDef.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// No use of def

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/NoJavaUtilDate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// No use of Java.util.date

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/NoTabCharacter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// No tab character

const { getIndentLength } = require("../utils");
import { getIndentLength } from "../utils";

const rule = {
scope: "file",
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SimpleDateFormatMissingLocale.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Simple Date Format missing locale

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterCatch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space after catch

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterComma.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Add space after a comma

const { getStringRange, addSpaceAfterChar } = require("../utils");
import { getStringRange,addSpaceAfterChar } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterFor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Space after for
const { getStringRange, addSpaceAfterChar } = require("../utils");
import { getStringRange,addSpaceAfterChar } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterIf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space after if

const { getStringRange, addSpaceAfterChar } = require("../utils");
import { getStringRange,addSpaceAfterChar } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterMethodCallName.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space after method call name

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterOpeningBrace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space after opening brace

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterSemicolon.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Add space after a semicolon

const { getStringRange, addSpaceAfterChar } = require("../utils");
import { getStringRange,addSpaceAfterChar } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterSwitch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space after switch

const { getStringRange, addSpaceAfterChar } = require("../utils");
import { getStringRange,addSpaceAfterChar } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAfterWhile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space after while

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceAroundOperator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Space around operators

const { getVariable, getVariableRange, addSpaceAroundChar } = require("../utils");
import { getVariable, getVariableRange, addSpaceAroundChar } from "../utils.js";

const rule = {
variables: [
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceBeforeClosingBrace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Space before opening brace
const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceBeforeOpeningBrace.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Space before opening brace
const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SpaceInsideParentheses.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// No space between parenthesis

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
fix: {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/SystemExit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// System.exit forbidden

const { getStringRange } = require("../utils");
import { getStringRange } from "../utils.js";

const rule = {
range: {
Expand Down
Loading

0 comments on commit f294f72

Please sign in to comment.