Skip to content

Commit

Permalink
refactor: addresses small linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Nov 23, 2024
1 parent 2ca5551 commit e72bc97
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion dist/cli/actions.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cli/normalize.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/parse/smcat/smcat-parser.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/render/dot/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions dist/render/smcat.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cli/actions.mts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function transform(pOptions: ICLIRenderOptions) {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function formatError(pError: any): string {
if (Boolean(pError.location)) {
if (pError.location) {
return `\n syntax error on line ${pError.location.start.line}, column ${pError.location.start.column}:\n ${pError.message}\n\n`;
}
return pError.message;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/attributes-parser.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by Peggy 4.1.1.
// @generated by Peggy 4.2.0.
//
// https://peggyjs.org/

Expand Down
4 changes: 2 additions & 2 deletions src/cli/normalize.mts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function determineOutputTo(
pInputFrom: string,
pOutputType: OutputType,
): string {
return pOutputTo ? pOutputTo : deriveOutputFromInput(pInputFrom, pOutputType);
return pOutputTo ?? deriveOutputFromInput(pInputFrom, pOutputType);
}

function determineInputType(
Expand Down Expand Up @@ -148,7 +148,7 @@ function determineDotAttributes(
pOptions: ILooseCLIRenderOptions,
pDotAttributes: keyof ILooseCLIRenderOptions,
): dotAttributesType {
return Boolean(pOptions?.[pDotAttributes]) &&
return pOptions?.[pDotAttributes] &&
typeof pOptions[pDotAttributes] === "string"
? (parseAttributes(pOptions[pDotAttributes]) as dotAttributesType)
: [];
Expand Down
9 changes: 4 additions & 5 deletions src/parse/parser-helpers.mts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ function extractUndeclaredStates(
pStateMachine: IStateMachine,
pKnownStateNames: string[],
): IState[] {
pKnownStateNames = pKnownStateNames
? pKnownStateNames
: getAlreadyDeclaredStates(pStateMachine);
pKnownStateNames =
pKnownStateNames ?? getAlreadyDeclaredStates(pStateMachine);

pStateMachine.states = pStateMachine?.states ?? [];
const lTransitions = pStateMachine?.transitions ?? [];
Expand Down Expand Up @@ -199,7 +198,7 @@ function parseTransitionExpression(pString: string): {

// @ts-expect-error match has no fallback because lTransitionExpressionRe will match
// any string (every part is optional)
const lMatchResult: RegExpMatchArray = pString.match(lTransitionExpressionRe);
const lMatchResult: RegExpMatchArray = lTransitionExpressionRe.exec(pString);
const lEventPos = 1;
const lConditionPos = 2;
const lActionPos = 3;
Expand Down Expand Up @@ -244,7 +243,7 @@ function extractAction(pActivityCandidate: string): {
type: string;
body: string;
} {
const lMatch = pActivityCandidate.match(TRIGGER_RE);
const lMatch = TRIGGER_RE.exec(pActivityCandidate);
const lTypePos = 1;
const lBodyPos = 2;

Expand Down
2 changes: 1 addition & 1 deletion src/parse/smcat/peg/smcat-parser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ state "state"
parserHelpers.setIf(lState, 'statemachine', statemachine);
parserHelpers.setIfNotEmpty(lState, 'note', notes);

if (Boolean(actions)) {
if (actions) {
parserHelpers.setIfNotEmpty(
lState,
'actions',
Expand Down
4 changes: 2 additions & 2 deletions src/parse/smcat/smcat-parser.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by Peggy 4.1.1.
// @generated by Peggy 4.2.0.
//
// https://peggyjs.org/

Expand Down Expand Up @@ -343,7 +343,7 @@ function peg$parse(input, options) {
parserHelpers.setIf(lState, 'statemachine', statemachine);
parserHelpers.setIfNotEmpty(lState, 'note', notes);

if (Boolean(actions)) {
if (actions) {
parserHelpers.setIfNotEmpty(
lState,
'actions',
Expand Down
2 changes: 1 addition & 1 deletion src/render/dot/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function nameTransition(pCounter) {
pTransition.to
}_${pCounter.nextAsString()}`;

if (Boolean(pTransition.note)) {
if (pTransition.note) {
pTransition.noteName = `note_${pTransition.name}`;
}

Expand Down
12 changes: 4 additions & 8 deletions src/render/dot/state-transformers.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function isOneOfTypes(pStringArray: string[]) {

function setLabel(pState: IExtendedState): IExtendedState {
const lState = structuredClone(pState);
lState.label = pState.label || pState.name;
lState.label = pState.label ?? pState.name;
return lState;
}

Expand Down Expand Up @@ -51,13 +51,13 @@ function flattenActions(pState: IExtendedState): IExtendedState {
};
}

return pState as IExtendedState;
return pState;
}

function flattenNote(pState: IExtendedState): IExtendedState {
if (pState.note) {
return {
...(pState as IExtendedState),
...pState,
noteFlattened: pState.note.join(""),
};
}
Expand Down Expand Up @@ -111,11 +111,7 @@ function tipForkJoinStates(pDirection: string) {
}

function flagParallelChildren(pState: IExtendedState): IExtendedState {
if (
pState.type === "parallel" &&
pState.statemachine &&
pState.statemachine.states
) {
if (pState.type === "parallel" && pState.statemachine?.states) {
pState.statemachine.states = pState.statemachine.states.map(
(pChildState: IState) =>
isType("regular")(pChildState)
Expand Down
2 changes: 1 addition & 1 deletion src/render/dot/utl.mts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function isCompositeSelf(
return (
pTransition.from === pTransition.to &&
pStateMachineModel.findStateByName(pTransition.from).statemachine &&
!(pTransition.type === "internal")
pTransition.type !== "internal"
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/render/scjson/make-valid-event-names.mts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function makeValidEventName(pCandidateEventName: string): string {
* @returns a valid SCXML events string
*/
export default (pCandidateEventNames?: string): string => {
const lCandidateEventNames = pCandidateEventNames || "";
const lCandidateEventNames = pCandidateEventNames ?? "";

if (lCandidateEventNames.length === 0) {
return "empty";
Expand Down
6 changes: 3 additions & 3 deletions src/render/smcat.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type {
ITransition,
} from "../../types/state-machine-cat.mjs";

const NAME_QUOTABLE = /;|,|{| |\[/;
const ACTIONS_QUOTABLE = /;|,|{/;
const LABEL_QUOTABLE = /;|{/;
const NAME_QUOTABLE = /[;,{[ ]/;
const ACTIONS_QUOTABLE = /[;,{}]/;
const LABEL_QUOTABLE = /[;{]/;

const RENDERABLE_STATE_ATTRIBUTES = [
"label",
Expand Down
2 changes: 1 addition & 1 deletion test/cli/actions.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function resetOutputDirectory() {
// if (!!pPair.input.argument){
// fs.unlinkSync(pPair.input.argument);
// }
if (Boolean(pPair.input.options.outputTo)) {
if (pPair.input.options.outputTo) {
fs.unlinkSync(pPair.input.options.outputTo);
}
} catch (pError) {
Expand Down

0 comments on commit e72bc97

Please sign in to comment.