-
Notifications
You must be signed in to change notification settings - Fork 0
Add ESLint configuration and refactor grefplus to use ES modules #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
751ab5c
628cd6c
26ad0bc
97a6905
ed325f1
08d52cf
73d53f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ alias ll='ls -ltrh' | |
## tools | ||
alias resource='source $HOME/.bashrc' | ||
alias clean='node $DEVROOT/dev-tools/src/clean/index.js' | ||
alias grefp='node $DEVROOT/dev-tools/src/grefplus' | ||
alias grefp='node $DEVROOT/dev-tools/src/grefplus/index.mjs' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Incorrect path in
🔗 Analysis chainLGTM! The alias update aligns with the PR objectives. The change from To ensure this change doesn't introduce breaking changes, please run the following verification: This script will verify the existence of the new file, check for ES module syntax, and attempt to run the 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Verify the existence of the new grefplus index.mjs file and check its content
# Test 1: Check if the new file exists
if [ -f "$DEVROOT/dev-tools/src/grefplus/index.mjs" ]; then
echo "index.mjs file exists."
else
echo "Error: index.mjs file not found!"
exit 1
fi
# Test 2: Check if the file contains ES module syntax
if grep -q "export" "$DEVROOT/dev-tools/src/grefplus/index.mjs"; then
echo "index.mjs contains ES module export syntax."
else
echo "Warning: index.mjs might not be using ES module syntax."
fi
# Test 3: Try running the grefp command with --help to check if it's working
if grefp --help > /dev/null 2>&1; then
echo "grefp command executed successfully."
else
echo "Error: grefp command failed to execute."
exit 1
fi
Length of output: 130 Script: #!/bin/bash
# Description: Output the value of the DEVROOT environment variable
echo "DEVROOT is set to: $DEVROOT"
Length of output: 48 Script: #!/bin/bash
# Description: Search for the index.mjs file in the repository
fd "index.mjs" .
Length of output: 41 |
||
alias branches='node $DEVROOT/dev-tools/src/branches' | ||
alias nt='node $DEVROOT/dev-tools/src/node-tools' | ||
alias yn='node $DEVROOT/dev-tools/src/yarn' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const { accessSync, constants, lstatSync } = require('fs'); | ||
const yargs = require('yargs'); | ||
const { DateTime } = require('luxon'); | ||
import { accessSync, constants, lstatSync } from 'node:fs'; | ||
import yargs from 'yargs/yargs'; | ||
import { DateTime } from 'luxon'; | ||
|
||
const options = { | ||
dateOptions: 'yyyy-MM-dd hh:mm:ss a' | ||
|
@@ -32,8 +32,7 @@ const cmdKeys = { | |
alias: 'r' | ||
, describe: 'root folder of development environment (/c/blah/blah). Default is DEVROOT' | ||
, type: 'array' | ||
// eslint-disable-next-line no-process-env | ||
, default: process.env.DEVROOT | ||
, default: [process.env.DEVROOT] | ||
} | ||
, 'date': { | ||
alias: 'd' | ||
|
@@ -46,13 +45,14 @@ const cmdKeys = { | |
/** | ||
* Validates from and to dates, | ||
* | ||
* @param {String} checkDate | ||
* @param {string} checkDate | ||
* @param {string} msg | ||
* @throws if date is not valid | ||
* @private | ||
*/ | ||
const validateDate = (checkDate, msg) => { | ||
try { | ||
const parsed = DateTime.fromFormat(checkDate, options.allowedFormat); | ||
const parsed = DateTime.fromFormat(checkDate.toString(), options.allowedFormat); | ||
if(!parsed.isValid) { | ||
throw new Error('unknown format'); | ||
} | ||
|
@@ -69,11 +69,11 @@ const validateDate = (checkDate, msg) => { | |
/** | ||
* Aborts build if dev root path does not exist | ||
* | ||
* @param {String} devRoot | ||
* @param {string[]} devRoot | ||
* @throws if path not accessible | ||
* @private | ||
*/ | ||
const validatePath = ({ devRoot }) => { | ||
const validatePath = (devRoot) => { | ||
let problematicRoot = null; | ||
|
||
devRoot.forEach(root => { | ||
|
@@ -108,24 +108,47 @@ const isFuture = (checkDate) => { | |
return _date > endOfToday; | ||
}; | ||
|
||
|
||
/** | ||
* | ||
* @param {string} argName | ||
* @param {boolean} [checkFuture] | ||
* @returns {boolean} | ||
* @throws if date is not valid | ||
*/ | ||
const validateArgDate = (argName, checkFuture) => { | ||
return (argv) => { | ||
const dt = `${argv[argName]}` || ''; | ||
if(dt) { | ||
validateDate(dt, `--${argName}`); | ||
if(checkFuture && isFuture(dt)) { | ||
throw new Error(`--${argName} cannot exceed current date`); | ||
} | ||
} | ||
return true; | ||
}; | ||
}; | ||
|
||
/** | ||
* Parse command line and configures options | ||
* | ||
* @param {Boolean} test - used for testing only | ||
* @param {Boolean} [test] - used for testing only | ||
*/ | ||
const setOptions = (test) => { | ||
const argv = test || yargs | ||
const argv = test || yargs(process.argv.slice(2)) | ||
// @ts-ignore | ||
.options(cmdKeys) | ||
Comment on lines
+138
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM with a minor correction needed The updates to the
However, there's a small issue to address: There's a typo in one of the - .check(validateArgDate('fromDate', true))
+ .check(validateArgDate('toDate')) Please correct this to ensure proper validation of the 'toDate' argument. Also applies to: 164-178 |
||
.version(false) | ||
.help(true) | ||
.strict(true) | ||
.check((_argv) => { | ||
// super secret shortcut | ||
if(!_argv.date && !_argv.fromDate && !_argv.toDate && Number.isInteger(_argv._[0])) { | ||
const days = Number(_argv._[0]); | ||
const _date = DateTime | ||
.fromFormat(_argv._[0], options.allowedFormat) | ||
.plus({ days: _argv._[0] }) | ||
.format('MM/DD/YY'); | ||
.fromFormat(days.toString(), options.allowedFormat) | ||
.plus({ days }) | ||
.toFormat('MM/DD/YY'); | ||
_argv.date = _date; | ||
Comment on lines
+147
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect date calculation in shortcut The changes to the date shortcut calculation don't fully address the previous issue:
Here's a suggested fix: const days = Number(_argv._[0]);
const _date = DateTime
.now()
.plus({ days })
.toFormat(options.allowedFormat);
_argv.date = _date; This change:
This approach ensures correct date calculation and consistent formatting. |
||
} | ||
Comment on lines
+147
to
152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logical Error: Incorrect date calculation in the shortcut The code attempts to parse Proposed fix: Start with the current date and add if(!_argv.date && !_argv.fromDate && !_argv.toDate && Number.isInteger(_argv._[0])) {
const days = Number(_argv._[0]);
const _date = DateTime
- .fromFormat(days.toString(), options.allowedFormat)
+ .now()
.plus({ days })
- .toFormat('MM/DD/YY');
+ .toFormat(options.allowedFormat);
_argv.date = _date;
} This change initializes the date from the current date and adds the specified number of days, then formats it using the allowed format.
|
||
else { | ||
|
@@ -138,53 +161,40 @@ const setOptions = (test) => { | |
} | ||
return true; | ||
}) | ||
.check(({ date }) => { | ||
if(date) { | ||
validateDate(date, '--date'); | ||
if(isFuture(date)) { | ||
throw new Error('--date cannot exceed current date'); | ||
} | ||
} | ||
return true; | ||
}) | ||
.check(({ fromDate }) => { | ||
if(fromDate) { | ||
validateDate(fromDate, '--from-date'); | ||
if(isFuture(fromDate)) { | ||
throw new Error('--from-date cannot exceed current date'); | ||
} | ||
} | ||
return true; | ||
}) | ||
.check(({ toDate }) => { | ||
if(toDate) { | ||
validateDate(toDate, '--to-date'); | ||
} | ||
return true; | ||
}) | ||
.check(({ folderNames }) => { | ||
.check(validateArgDate('date', true)) | ||
.check(validateArgDate('fromDate', true)) | ||
.check(validateArgDate('fromDate', true)) | ||
.check(validateArgDate('toDate')) | ||
.check((argv) => { | ||
const folderNames = Array.isArray(argv.folderNames) ? argv.folderNames : []; | ||
if(folderNames && !folderNames.length) { | ||
throw new Error('--folder-names requires at least one name'); | ||
} | ||
return true; | ||
}) | ||
.check(validatePath) | ||
.check(argv => { | ||
const devRoot = argv.devRoot; | ||
return validatePath(devRoot); | ||
}) | ||
.argv; | ||
|
||
// @ts-ignore | ||
if(argv.date) { | ||
// @ts-ignore | ||
const date = DateTime.fromFormat(argv.date, options.allowedFormat); | ||
module.exports.options.fromDate = date.startOf('day'); | ||
module.exports.options.toDate = date.endOf('day'); | ||
options.fromDate = date.startOf('day'); | ||
options.toDate = date.endOf('day'); | ||
} | ||
else { | ||
module.exports.options.fromDate = argv.fromDate ? DateTime.fromFormat(argv.fromDate, options.allowedFormat).startOf('day') : null; | ||
module.exports.options.toDate = argv.toDate ? DateTime.fromFormat(argv.toDate, options.allowedFormat).endOf('day') : null; | ||
// @ts-ignore | ||
options.fromDate = argv.fromDate ? DateTime.fromFormat(argv.fromDate, options.allowedFormat).startOf('day') : null; | ||
// @ts-ignore | ||
options.toDate = argv.toDate ? DateTime.fromFormat(argv.toDate, options.allowedFormat).endOf('day') : null; | ||
} | ||
module.exports.options.devRoot = argv.devRoot; | ||
module.exports.options.folderNames = argv.folderNames || []; | ||
// @ts-ignore | ||
options.devRoot = argv.devRoot; | ||
// @ts-ignore | ||
options.folderNames = argv.folderNames || []; | ||
}; | ||
|
||
module.exports = { | ||
options | ||
, setOptions | ||
}; | ||
export { options, setOptions }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Yarn is not configured in the workflow
The workflow currently lacks steps to install or configure Yarn, which results in the
yarn
commands failing. To ensure Yarn is available and correctly set up in the CI environment, please consider the following changes:Enable Corepack and Set Yarn Version:
Correct the Install Command Flag:
These adjustments will ensure that Yarn is properly installed and configured, and that the correct flags are used during dependency installation.
🔗 Analysis chain
Verify Yarn version and correct flag usage
The change from
--frozen-lockfile
to---immutable
suggests a migration from Yarn 1.x to Yarn 2+ (Berry). This is a good practice as it ensures more deterministic builds. However, there are two points to consider:The use of three dashes (
---
) for theimmutable
flag is unusual. Typically, long-form flags use two dashes (--
). This might be a typo and should be corrected to--immutable
.The workflow doesn't explicitly specify the Yarn version. To ensure consistency across different environments and prevent potential issues, it's recommended to pin the Yarn version.
Consider applying the following changes:
To confirm the correct Yarn version and available flags, you can run:
This will help verify the correct Yarn version is being used and the available flags for the
install
command.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 182
Script:
Length of output: 170
Script:
Length of output: 101