Skip to content

Commit

Permalink
wip/change ~ fix biome linter complaints
Browse files Browse the repository at this point in the history
- lint/complexity/useLiteralKeys
- lint/correctness/noConstructorReturn
- lint/style/noParameterAssign
- lint/style/useTemplate
- lint/suspicious/noExplicitAny
- lint/suspicious/noRedundantUseStrict
  • Loading branch information
rivy committed Nov 27, 2023
1 parent 3e3f730 commit daaaa7c
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 106 deletions.
6 changes: 3 additions & 3 deletions .commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

/* @prettier */ // note: (dprint) {.dprint.json}.prettier.associations should contain the name of this file

const isNPMTestDist = !!process.env['npm_config_test_dist'];
const isTestDist = !!process.env['test_dist'];
const isTestRelease = !!process.env['test_release'];
const isNPMTestDist = !!process.env.npm_config_test_dist;
const isTestDist = !!process.env.test_dist;
const isTestRelease = !!process.env.test_release;

/** Relax linting rules/strictures (for development; *not* when submitting for distribution/release). */
const relaxedReview = !(isNPMTestDist || isTestDist || isTestRelease);
Expand Down
39 changes: 21 additions & 18 deletions eg/show-paths.cjs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// deno-fmt-ignore-file ## prefer customized `prettier` formatting
// # spell-checker:ignore APPNAME
/* eslint-env es6, node */
'use strict';
// 'use strict';

const path = require('path');

Expand All @@ -20,27 +20,30 @@ xdgAppPaths.log = function (dirOptions) {
return typeof x;
}

if (typeOf(dirOptions) === 'boolean') {
dirOptions = { isolated: dirOptions };
}

if (
typeOf(dirOptions) !== 'object' ||
dirOptions === null ||
typeOf(dirOptions.isolated) !== 'boolean'
) {
dirOptions = { isolated: self.$isolated() };
}

return path.join(self.state(dirOptions), (dirOptions.isolated ? '' : self.$name() + '-') + 'log');
const dirOptions_ = (() => {
if (typeOf(dirOptions) === 'boolean') {
return { isolated: dirOptions };
}
if (
typeOf(dirOptions) !== 'object' ||
dirOptions == null ||
typeOf(dirOptions.isolated) !== 'boolean'
) {
return { isolated: self.$isolated() };
}
})();

return path.join(
self.state(dirOptions_),
`${dirOptions_.isolated ? '' : `${self.$name()}-`} + 'log'`,
);
};

function showObjectEntries(obj) {
var strings = [];
Object.keys(obj).forEach((key) => {
const strings = Object.keys(obj).map((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
strings.push(key + ' = ' + val);
return `${key} = ${val}`;
});
return strings.join('\n');
}
Expand All @@ -53,7 +56,7 @@ console.log('appPaths.log(false):', xdgAppPaths.log(false));
console.log('appPaths.log(true):', xdgAppPaths.log(true));

// eslint-disable-next-line functional/immutable-data
delete process.env.XDG_CONFIG_HOME;
process.env.XDG_CONFIG_HOME = void 0;
// eslint-disable-next-line functional/no-let
let p = require(xdgAppPathsModulePath)('dross');

Expand Down
46 changes: 23 additions & 23 deletions eg/show-paths.esm.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// deno-fmt-ignore-file ## prefer customized `prettier` formatting
// # spell-checker:ignore APPNAME
/* eslint-env es6, node */
'use strict';
// 'use strict';

import path from 'path';
import { inspect } from 'util';
Expand All @@ -11,13 +11,10 @@ import { inspect } from 'util';
import xdgAppPaths from '../dist/cjs/esm-wrapper/mod.esm.js';

function objectEntries(obj) {
const map = {};
Object.keys(obj).forEach((key) => {
return Object.keys(obj).map((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
map[key] = val;
return typeof value === 'function' ? value() : value;
});
return map;
}

// Extend appPaths with a "log" location function
Expand All @@ -28,27 +25,30 @@ xdgAppPaths.log = function (dirOptions = null) {
return typeof x;
}

if (typeOf(dirOptions) === 'boolean') {
dirOptions = { isolated: dirOptions };
}

if (
typeOf(dirOptions) !== 'object' ||
dirOptions === null ||
typeOf(dirOptions.isolated) !== 'boolean'
) {
dirOptions = { isolated: self.$isolated() };
}

return path.join(self.state(dirOptions), (dirOptions.isolated ? '' : self.$name() + '-') + 'log');
const dirOptions_ = (() => {
if (typeOf(dirOptions) === 'boolean') {
return { isolated: dirOptions };
}
if (
typeOf(dirOptions) !== 'object' ||
dirOptions == null ||
typeOf(dirOptions.isolated) !== 'boolean'
) {
return { isolated: self.$isolated() };
}
})();

return path.join(
self.state(dirOptions_),
`${dirOptions_.isolated ? '' : `${self.$name()}-`} + 'log'`,
);
};

function showObjectEntries(obj) {
var strings = [];
Object.keys(obj).forEach((key) => {
const strings = Object.keys(obj).map((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
strings.push(key + ' = ' + val);
return `${key} = ${val}`;
});
return strings.join('\n');
}
Expand All @@ -60,7 +60,7 @@ console.log('appPaths.log():', xdgAppPaths.log());
console.log('appPaths.log(false):', xdgAppPaths.log(false));
console.log('appPaths.log(true):', xdgAppPaths.log(true));

delete process.env.XDG_CONFIG_HOME;
process.env.XDG_CONFIG_HOME = void 0;
// eslint-disable-next-line functional/no-let
let p = xdgAppPaths('dross');

Expand Down
22 changes: 10 additions & 12 deletions eg/show-paths.local.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const deno = Deno;

const inspect = deno.inspect;

/* eslint-disable @typescript-eslint/no-explicit-any , functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-disable functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // deno-type import
Expand All @@ -23,14 +23,12 @@ import xdgAppPaths from '../src/mod.deno.ts';
// @ts-ignore // deno-type import
import type { DirOptions, XDGAppPaths } from '../src/mod.deno.ts';

function objectEntries(obj: any) {
const map: any = {};
Object.keys(obj).forEach((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
map[key] = val;
function objectEntries(obj: unknown) {
const obj_ = obj as { readonly [key: string]: unknown };
return Object.keys(obj_).map((key) => {
const value = obj_[key];
return typeof value === 'function' ? value() : value;
});
return map;
}

// eslint-disable-next-line functional/prefer-readonly-type
Expand All @@ -39,9 +37,9 @@ type XDGAppPathsWithLog = XDGAppPaths & { log: (dirOptions?: DirOptions | boolea
// Extend appPaths with a "log" location
(xdgAppPaths as XDGAppPathsWithLog).log = function log(dirOptions?: DirOptions | boolean) {
const self = xdgAppPaths;
dirOptions = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions === 'boolean' ? dirOptions : dirOptions.isolated || true;
return path.join(self.state(isolated), (isolated ? '' : self.$name() + '-') + 'log');
const dirOptions_ = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions_ === 'boolean' ? dirOptions_ : dirOptions_.isolated || true;
return path.join(self.state(isolated), `${isolated ? '' : `${self.$name()}-`} + 'log'`);
};

console.log('appPaths:', inspect(xdgAppPaths));
Expand Down Expand Up @@ -79,4 +77,4 @@ p = xdgAppPaths({ name: 'fluffy', isolated: false });
console.log('p:', inspect(p));
console.log(objectEntries(p));

/* eslint-enable @typescript-eslint/no-explicit-any , functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-enable functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */
22 changes: 10 additions & 12 deletions eg/show-paths.remote(CDN).deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// --allow-env (transitive from 'xdg-app-paths')
// --allow-read

/* eslint-disable @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-disable @typescript-eslint/ban-ts-comment , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */

// @ts-ignore // deno-type URL import
import * as path from 'https://deno.land/std@0.150.0/path/mod.ts';
Expand All @@ -21,14 +21,12 @@ import xdgAppPaths from 'https://cdn.jsdelivr.net/gh/rivy/js.xdg-app-paths@v8.1.
// @ts-ignore // deno-type import
import type { DirOptions, XDGAppPaths } from '../src/mod.deno.ts';

function objectEntries(obj: any) {
const map: any = {};
Object.keys(obj).forEach((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
map[key] = val;
function objectEntries(obj: unknown) {
const obj_ = obj as { readonly [key: string]: unknown };
return Object.keys(obj_).map((key) => {
const value = obj_[key];
return typeof value === 'function' ? value() : value;
});
return map;
}

// eslint-disable-next-line functional/prefer-readonly-type
Expand All @@ -37,9 +35,9 @@ type XDGAppPathsWithLog = XDGAppPaths & { log: (dirOptions?: DirOptions | boolea
// Extend appPaths with a "log" location
(xdgAppPaths as XDGAppPathsWithLog).log = function log(dirOptions?: DirOptions | boolean) {
const self = xdgAppPaths;
dirOptions = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions === 'boolean' ? dirOptions : dirOptions.isolated || true;
return path.join(self.state(isolated), (isolated ? '' : self.$name() + '-') + 'log');
const dirOptions_ = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions_ === 'boolean' ? dirOptions_ : dirOptions_.isolated || true;
return path.join(self.state(isolated), `${isolated ? '' : `${self.$name()}-`}log`);
};

console.log('appPaths:', inspect(xdgAppPaths));
Expand Down Expand Up @@ -77,4 +75,4 @@ p = xdgAppPaths({ name: 'fluffy', isolated: false });
console.log('p:', inspect(p));
console.log(objectEntries(p));

/* eslint-enable @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-enable @typescript-eslint/ban-ts-comment , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */
22 changes: 10 additions & 12 deletions eg/show-paths.remote.deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// --allow-env (transitive from 'xdg-app-paths')
// --allow-read

/* eslint-disable @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-disable @typescript-eslint/ban-ts-comment , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */

// @ts-ignore // deno-type URL import
import * as path from 'https://deno.land/std@0.150.0/path/mod.ts';
Expand All @@ -21,14 +21,12 @@ import xdgAppPaths from 'https://deno.land/x/xdg_app_paths@v8.1.0/src/mod.deno.t
// @ts-ignore // deno-type import
import type { DirOptions, XDGAppPaths } from '../src/mod.deno.ts';

function objectEntries(obj: any) {
const map: any = {};
Object.keys(obj).forEach((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
map[key] = val;
function objectEntries(obj: unknown) {
const obj_ = obj as { readonly [key: string]: unknown };
return Object.keys(obj_).map((key) => {
const value = obj_[key];
return typeof value === 'function' ? value() : value;
});
return map;
}

// eslint-disable-next-line functional/prefer-readonly-type
Expand All @@ -37,9 +35,9 @@ type XDGAppPathsWithLog = XDGAppPaths & { log: (dirOptions?: DirOptions | boolea
// Extend appPaths with a "log" location
(xdgAppPaths as XDGAppPathsWithLog).log = function log(dirOptions?: DirOptions | boolean) {
const self = xdgAppPaths;
dirOptions = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions === 'boolean' ? dirOptions : dirOptions.isolated || true;
return path.join(self.state(isolated), (isolated ? '' : self.$name() + '-') + 'log');
const dirOptions_ = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions_ === 'boolean' ? dirOptions_ : dirOptions_.isolated || true;
return path.join(self.state(isolated), `${isolated ? '' : `${self.$name()}-`}log`);
};

console.log('appPaths:', inspect(xdgAppPaths));
Expand Down Expand Up @@ -77,4 +75,4 @@ p = xdgAppPaths({ name: 'fluffy', isolated: false });
console.log('p:', inspect(p));
console.log(objectEntries(p));

/* eslint-enable @typescript-eslint/ban-ts-comment , @typescript-eslint/no-explicit-any , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-enable @typescript-eslint/ban-ts-comment , functional/immutable-data , import/order , no-console , security-node/detect-crlf , security/detect-object-injection */
24 changes: 11 additions & 13 deletions eg/show-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
import path from 'path';
import { inspect } from 'util';

/* eslint-disable @typescript-eslint/no-explicit-any , functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-disable functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */

import xdgAppPaths from '../dist/cjs/mod.cjs';
import type { DirOptions, XDGAppPaths } from '../src/mod.esm';

function objectEntries(obj: any) {
const map: any = {};
Object.keys(obj).forEach((key) => {
const value = obj[key];
const val = typeof value === 'function' ? value() : value;
map[key] = val;
function objectEntries(obj: unknown) {
const obj_ = obj as { readonly [key: string]: unknown };
return Object.keys(obj_).map((key) => {
const value = obj_[key];
return typeof value === 'function' ? value() : value;
});
return map;
}

// eslint-disable-next-line functional/prefer-readonly-type
Expand All @@ -24,9 +22,9 @@ type XDGAppPathsWithLog = XDGAppPaths & { log: (dirOptions?: DirOptions | boolea
// Extend appPaths with a "log" location
(xdgAppPaths as XDGAppPathsWithLog).log = function log(dirOptions?: DirOptions | boolean) {
const self = xdgAppPaths;
dirOptions = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions === 'boolean' ? dirOptions : dirOptions.isolated || true;
return path.join(self.state(isolated), (isolated ? '' : self.$name() + '-') + 'log');
const dirOptions_ = dirOptions ?? { isolated: self.$isolated() };
const isolated = typeof dirOptions_ === 'boolean' ? dirOptions_ : dirOptions_.isolated || true;
return path.join(self.state(isolated), `${isolated ? '' : `${self.$name()}-`} + 'log'`);
};

console.log('appPaths:', inspect(xdgAppPaths));
Expand All @@ -36,7 +34,7 @@ console.log(objectEntries(xdgAppPaths));
console.log('appPaths.log(false):', (xdgAppPaths as XDGAppPathsWithLog).log(false));
console.log('appPaths.log(true):', (xdgAppPaths as XDGAppPathsWithLog).log(true));

delete process.env.XDG_CONFIG_HOME;
process.env.XDG_CONFIG_HOME = void 0;
// eslint-disable-next-line functional/no-let
let p = xdgAppPaths('dross');

Expand All @@ -58,4 +56,4 @@ p = xdgAppPaths({ name: 'fluffy', isolated: false });
console.log('p:', inspect(p));
console.log(objectEntries(p));

/* eslint-enable @typescript-eslint/no-explicit-any , functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */
/* eslint-enable functional/immutable-data , no-console , security-node/detect-crlf , security/detect-object-injection */
7 changes: 4 additions & 3 deletions src/lib/XDGAppPaths.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// deno-fmt-ignore-file ## prefer customized `prettier` formatting
// # spell-checker:ignore APPDATA LOCALAPPDATA MacOS tempdir
/* eslint-env es6, node */
'use strict';
// 'use strict';

import { Platform } from '../platform-adapters/_base.js';

Expand Down Expand Up @@ -133,8 +133,8 @@ function Adapt(adapter_: Platform.Adapter): { readonly XDGAppPaths: XDGAppPaths
};

function isIsolated(dirOptions?: DirOptions | boolean): boolean {
dirOptions = dirOptions ?? { isolated: isolated_ };
const isolated = isBoolean(dirOptions) ? dirOptions : dirOptions.isolated ?? isolated_;
const dirOptions_ = dirOptions ?? { isolated: isolated_ };
const isolated = isBoolean(dirOptions_) ? dirOptions_ : dirOptions_.isolated ?? isolated_;
return isolated;
}

Expand Down Expand Up @@ -176,6 +176,7 @@ function Adapt(adapter_: Platform.Adapter): { readonly XDGAppPaths: XDGAppPaths
.map((s) => path.join(s, finalPathSegment(dirOptions))) as readonly string[];
};

// biome-ignore lint/correctness/noConstructorReturn: return class as a callable Function object
return XDGAppPaths as XDGAppPaths;
}
}
Expand Down
Loading

0 comments on commit daaaa7c

Please sign in to comment.