Skip to content

Commit

Permalink
fix: linted
Browse files Browse the repository at this point in the history
  • Loading branch information
zdm committed Jan 24, 2024
1 parent da159cd commit 4f30fde
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 99 deletions.
8 changes: 4 additions & 4 deletions __tests__/001-git.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ describe( "git-branch-parser", () => {

for ( let n = 0; n < tests.length; n++ ) {
test( "test_" + n, () => {
const match = tests[n][0].match( BRANCH_RE );
const match = tests[ n ][ 0 ].match( BRANCH_RE );

if ( !match ) throw Error( `Parsing error: ` + tests[n][0] );
if ( !match ) throw Error( `Parsing error: ` + tests[ n ][ 0 ] );

for ( const prop in tests[n][1] ) {
expect( tests[n][1][prop] ).toBe( match.groups[prop] );
for ( const prop in tests[ n ][ 1 ] ) {
expect( tests[ n ][ 1 ][ prop ] ).toBe( match.groups[ prop ] );
}
} );
}
Expand Down
18 changes: 9 additions & 9 deletions docs/assets/theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ class Theme {
for ( let n = 0; n < blocks.length; n++ ) {

// code block start
if ( blocks[n].startsWith( "```" ) ) continue;
if ( blocks[ n ].startsWith( "```" ) ) continue;

// code block body
if ( n && blocks[n - 1].startsWith( "```" ) ) continue;
if ( n && blocks[ n - 1 ].startsWith( "```" ) ) continue;

blocks[n] = blocks[n].replaceAll( /<([\w.]+)(\[\])?\\>/g, ( match, type, array ) => {
blocks[ n ] = blocks[ n ].replaceAll( /<([\w.]+)(\[\])?\\>/g, ( match, type, array ) => {
if ( type in types ) {
return `<[${ type }${ array ?? "" }](${ types[type] })\\>`;
return `<[${ type }${ array ?? "" }](${ types[ type ] })\\>`;
}
else {
return match;
Expand Down Expand Up @@ -176,19 +176,19 @@ class Theme {
const tag = heading.tagName,
level = +tag.substring( 1 );

levels[level] = level;
levels[ level ] = level;
}

const sortedLevels = Object.keys( levels ).sort();

for ( let n = 0; n < sortedLevels.length; n++ ) {
levels[sortedLevels[n]] = n + 1;
levels[ sortedLevels[ n ] ] = n + 1;
}

// create toc
for ( const heading of headings ) {
const tag = heading.tagName,
level = levels[tag.substring( 1 )];
level = levels[ tag.substring( 1 ) ];

let list;

Expand All @@ -197,7 +197,7 @@ class Theme {
for ( let n = 0; n < level - currentLevel; n++ ) {
list = document.createElement( "ul" );

lists[lists.length - 1].appendChild( list );
lists[ lists.length - 1 ].appendChild( list );

lists.push( list );
}
Expand All @@ -211,7 +211,7 @@ class Theme {
currentLevel = level;
}

list = lists[lists.length - 1];
list = lists[ lists.length - 1 ];

const link = heading.querySelector( "a" ),
li = document.createElement( "li" ),
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/git/pre-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class extends Command {
if ( !res1.ok ) this._throwError( `Unable to update git index` );

// update working tree, if file wasn't modified after add and wasn't removed
if ( !modified[filename] && fs.existsSync( filename ) ) fs.writeFileSync( filename, res.data );
if ( !modified[ filename ] && fs.existsSync( filename ) ) fs.writeFileSync( filename, res.data );
}

// report
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export default class extends Command {
const osFilter = process.cli.options.android || process.cli.options.electron || process.cli.options.ios;

for ( const os in icons ) {
if ( osFilter && !process.cli.options[os] ) continue;
if ( osFilter && !process.cli.options[ os ] ) continue;

for ( const spec of icons[os] ) {
for ( const spec of icons[ os ] ) {
const img = await jimp.read( resources + "/" + spec.source );

for ( const [ name, target ] of Object.entries( spec.targets ) ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ Ignored directories:
}

// read patterns from stdin
else if ( patterns.length === 1 && patterns[0] === "-" ) {
else if ( patterns.length === 1 && patterns[ 0 ] === "-" ) {
patterns = await this.#readStdin();
}

const lint = new Lint( patterns, {
"cwd": "",
"useLintIgnore": process.cli.options.lintignore,
"verbose": process.cli.options.verbose,
"reportIgnored": process.cli.options["report-ignored"],
"reportIgnored": process.cli.options[ "report-ignored" ],
} );

const res = await lint.run( process.cli.options.action );
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class extends Command {

// public
async run () {
const workspace = process.env["SOFTVISIO_CLI_WORKSPACE_" + process.platform];
const workspace = process.env[ "SOFTVISIO_CLI_WORKSPACE_" + process.platform ];

if ( !workspace ) this._throwError( `No workspace configured` );

Expand Down Expand Up @@ -100,7 +100,7 @@ export default class extends Command {
if ( !status.ok ) this._throwError( `Git error: ` + status );
status = status.data;

const currentBranchPushStatus = status.pushStatus[status.branch];
const currentBranchPushStatus = status.pushStatus[ status.branch ];

const isDirty = status.isDirty || currentBranchPushStatus,
isUnreleased = ( !status.currentVersion.isNull && status.currentVersionDistance ) || ( !status.branch && status.abbrev );
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class extends Command {
if ( !rootPackage ) this._throwError( "Unable to find root package" );

// prepeare release type
const preRelease = PRERELEASE[process.cli.arguments["pre-release"]] || process.cli.arguments["pre-release"];
const preRelease = PRERELEASE[ process.cli.arguments[ "pre-release" ] ] || process.cli.arguments[ "pre-release" ];

const res = await rootPackage.publish( preRelease, process.cli.options.force );

Expand Down
8 changes: 4 additions & 4 deletions lib/commands/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export default class extends Command {

decoder.on( "data", async msg => {
try {
const res = await this["API_" + msg[2]]( ...msg[3] );
const res = await this[ "API_" + msg[ 2 ] ]( ...msg[ 3 ] );

socket.write( msgpack.encode( [ 1, msg[1], null, res ] ) );
socket.write( msgpack.encode( [ 1, msg[ 1 ], null, res ] ) );
}
catch ( e ) {
console.log( e );

socket.write( msgpack.encode( [ 1, msg[1], "error", null ] ) );
socket.write( msgpack.encode( [ 1, msg[ 1 ], "error", null ] ) );
}
} );

Expand All @@ -59,7 +59,7 @@ export default class extends Command {
data.data.replaceAll( `"`, "&quot;" );
data.data.replaceAll( `'`, "&#39;" );

if ( data.font ) data.font = data.font.split( ":" )[0].replaceAll( "_", " " );
if ( data.font ) data.font = data.font.split( ":" )[ 0 ].replaceAll( "_", " " );

const html = `
<html>
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Stable release (latest): ${ ansi.hl( status.releases.lastStableVersion.isNull ?
Last release (next): ${ ansi.hl( status.releases.lastVersion.isNull ? "-" : status.releases.lastVersion ) }
Is dirty: ${ status.isDirty ? ansi.error( " DIRTY " ) : ansi.ok( " COMMITED " ) }
Not pushed commits: ${ Object.keys( status.pushStatus )
.map( branch => branch + ":" + ( status.pushStatus[branch] ? ansi.error( " " + status.pushStatus[branch] + " " ) : ansi.ok( " PUSHED " ) ) )
.map( branch => branch + ":" + ( status.pushStatus[ branch ] ? ansi.error( " " + status.pushStatus[ branch ] + " " ) : ansi.ok( " PUSHED " ) ) )
.join( ", " ) }
Unreleased commits: ${ status.currentVersionDistance ? ( !status.currentVersion.isNull ? ansi.error( " " + status.currentVersionDistance + " " ) : status.currentVersionDistance ) : ansi.ok( " RELEASED " ) }
`.trim() );
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/test/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export default class extends Command {
"level": process.cli.options.level,
"json": process.cli.options.json,

"modulePattern": process.cli.arguments["module-pattern"],
"firstLevelPattern": process.cli.arguments["first-level-pattern"],
"secondLevelPattern": process.cli.arguments["second-level-pattern"],
"modulePattern": process.cli.arguments[ "module-pattern" ],
"firstLevelPattern": process.cli.arguments[ "first-level-pattern" ],
"secondLevelPattern": process.cli.arguments[ "second-level-pattern" ],
};
}
}
20 changes: 10 additions & 10 deletions lib/commands/test/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default class extends Command {
const { "default": fs } = await import( "fs" );

// test single module
if ( process.cli.arguments["module-pattern"] && fs.existsSync( process.cli.arguments["module-pattern"] ) && fs.statSync( process.cli.arguments["module-pattern"] ).isFile() ) {
return await this.#testSingleModule( process.cli.arguments["module-pattern"] );
if ( process.cli.arguments[ "module-pattern" ] && fs.existsSync( process.cli.arguments[ "module-pattern" ] ) && fs.statSync( process.cli.arguments[ "module-pattern" ] ).isFile() ) {
return await this.#testSingleModule( process.cli.arguments[ "module-pattern" ] );
}

const packages = [];
Expand Down Expand Up @@ -123,14 +123,14 @@ export default class extends Command {
return {
"benchmarks": process.cli.options.benchmarks,
"verbose": process.cli.options.verbose,
"showSkipped": process.cli.options["show-skipped"],
"showPassed": process.cli.options["show-passed"],
"showStackTrace": process.cli.options["show-stack-trace"],
"showConsoleLog": process.cli.options["show-console-log"],

"modulePattern": process.cli.arguments["module-pattern"],
"firstLevelPattern": process.cli.arguments["first-level-pattern"],
"secondLevelPattern": process.cli.arguments["second-level-pattern"],
"showSkipped": process.cli.options[ "show-skipped" ],
"showPassed": process.cli.options[ "show-passed" ],
"showStackTrace": process.cli.options[ "show-stack-trace" ],
"showConsoleLog": process.cli.options[ "show-console-log" ],

"modulePattern": process.cli.arguments[ "module-pattern" ],
"firstLevelPattern": process.cli.arguments[ "first-level-pattern" ],
"secondLevelPattern": process.cli.arguments[ "second-level-pattern" ],
};
}
}
16 changes: 8 additions & 8 deletions lib/get-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default class GetText {
const locale = {
"l10n": ( msgId, plural, pluralNumber ) => {
this.#poFile.addMessages( {
[msgId]: {
[ msgId ]: {
"pluralId": plural,
"references": [ this.#relativePath ],
},
Expand All @@ -147,7 +147,7 @@ export default class GetText {

"l10nt": ( msgId, plural, pluralNumber ) => {
this.#poFile.addMessages( {
[msgId]: {
[ msgId ]: {
"pluralId": plural,
"references": [ this.#relativePath ],
},
Expand Down Expand Up @@ -198,11 +198,11 @@ export default class GetText {
}

// at least 1 argument is required
if ( !node.arguments?.[0] ) return;
if ( !node.arguments?.[ 0 ] ) return;

// ejs
if ( method === "ejs" ) {
const arg = node.arguments[0];
const arg = node.arguments[ 0 ];

let template;

Expand Down Expand Up @@ -244,16 +244,16 @@ export default class GetText {
};

// message id
const msgId = this.#parseMessage( node.arguments[0], {
const msgId = this.#parseMessage( node.arguments[ 0 ], {
start,
} );
if ( !msgId.value ) return;
id = msgId.value;
if ( msgId.isTemplate ) message.flags = [ "javascript-format" ];

// plural
if ( node.arguments[1] ) {
const plural = this.#parseMessage( node.arguments[1], {
if ( node.arguments[ 1 ] ) {
const plural = this.#parseMessage( node.arguments[ 1 ], {
start,
} );
if ( !plural.value ) return;
Expand All @@ -278,7 +278,7 @@ export default class GetText {

message.references = reference;

this.#poFile.addMessages( { [id]: message } );
this.#poFile.addMessages( { [ id ]: message } );
}

#parseMessage ( node, { start } = {} ) {
Expand Down
12 changes: 6 additions & 6 deletions lib/git/changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,24 @@ export default class Changes {
commit = new Commit( commit );

// commit is already indexed
if ( index[commit.subjectId] ) {
if ( index[ commit.subjectId ] ) {

// do not replace breaking commits in the index
if ( index[commit.subjectId].isBreaking || !commit.isBreaking ) {
index[commit.subjectId].commits.push( commit );
if ( index[ commit.subjectId ].isBreaking || !commit.isBreaking ) {
index[ commit.subjectId ].commits.push( commit );
}

// replace indexed commit with the breaking commit
else {
commit.commits.unshift( ...index[commit.subjectId].commits );
commit.commits.unshift( ...index[ commit.subjectId ].commits );

index[commit.subjectId] = commit;
index[ commit.subjectId ] = commit;
}
}

// first commit
else {
index[commit.subjectId] = commit;
index[ commit.subjectId ] = commit;
}
}

Expand Down
16 changes: 8 additions & 8 deletions lib/lint/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class LintFile {
// unknown
if ( !type ) return;

return !!TYPES[type.type];
return !!TYPES[ type.type ];
}

async run ( action ) {
Expand All @@ -140,7 +140,7 @@ export default class LintFile {
if ( mimeType ) type = mimeType.type;
}

if ( type ) this.#type = TYPES[type];
if ( type ) this.#type = TYPES[ type ];
}

if ( !this.#type && !this.#processUnsupported ) return result( [ 202, "File ignored" ] );
Expand Down Expand Up @@ -324,7 +324,7 @@ export default class LintFile {
"warnIgnored": true,
} );

if ( report[0].output != null ) this.#data = report[0].output;
if ( report[ 0 ].output != null ) this.#data = report[ 0 ].output;

// append log
var log = "",
Expand All @@ -341,7 +341,7 @@ export default class LintFile {
},
} );

for ( const msg of report[0].messages.sort( ( a, b ) => b.severity - a.severity || a.line - b.line || a.column - b.column ) ) {
for ( const msg of report[ 0 ].messages.sort( ( a, b ) => b.severity - a.severity || a.line - b.line || a.column - b.column ) ) {
let severity;

if ( msg.severity === 1 ) {
Expand Down Expand Up @@ -434,14 +434,14 @@ export default class LintFile {
}

async #cssnano ( preset ) {
if ( !POSTCSS_CACHE[preset] ) {
if ( !POSTCSS_CACHE[ preset ] ) {
postcss ??= ( await import( "postcss" ) ).default;
cssnano ??= ( await import( "Cssnano" ) ).default;

POSTCSS_CACHE[preset] = postcss( [ cssnano( { "preset": CSSNANO_PRESETS[preset] } ) ] );
POSTCSS_CACHE[ preset ] = postcss( [ cssnano( { "preset": CSSNANO_PRESETS[ preset ] } ) ] );
}

const res = await POSTCSS_CACHE[preset].process( this.#data, { "from": null } );
const res = await POSTCSS_CACHE[ preset ].process( this.#data, { "from": null } );

this.#data = res.toString();

Expand Down Expand Up @@ -483,7 +483,7 @@ export default class LintFile {
}

#replaceEndOfLine ( endOfLine ) {
const eol = EOL[endOfLine];
const eol = EOL[ endOfLine ];

if ( !eol ) return;

Expand Down
Loading

0 comments on commit 4f30fde

Please sign in to comment.