Skip to content

Commit d48a8c0

Browse files
committedJul 3, 2023
style: "Rearrange order of task definitions and disable ESLint on non-literal fs filename"
Rearranged the order of task definitions in many "group" files to achieve consistent code organization. The change doesn't affect the functionality of the files. Also, ESLint is now disabled for non-literal file system filename invocations for better runtime security. Several eslint errors of security/detect-non-literal-fs-filename, security/detect-object-injection were also fixed throughout the diff. Some parameters are reordered in some files to make the code base more consistent and enhance readability. Signed-off-by: prisis <d.bannert@anolilab.de>
1 parent dcd5718 commit d48a8c0

File tree

21 files changed

+143
-115
lines changed

21 files changed

+143
-115
lines changed
 

‎babel.config.cjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
module.exports = {
2+
plugins: ["transform-es2015-modules-commonjs"],
23
presets: [
34
[
45
"@babel/preset-env",
56
{
7+
modules: "auto",
68
targets: {
79
node: "current",
810
},
9-
modules: "auto",
1011
},
1112
],
1213
],
13-
plugins: ["transform-es2015-modules-commonjs"],
1414
};

‎packages/babel-preset/src/index.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ const preset = declare((api: BabelAPI, options: Options): Record<string, any> =>
4141
api.assertVersion("^7.13");
4242

4343
const {
44-
modules = "auto",
45-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
46-
targets,
47-
removePropTypes: removePropertyTypes = false,
44+
corejs = false,
4845
loose = true,
4946
looseClasses = true,
50-
looseObjectRestSpread = true,
5147
looseComputedProperties = true,
48+
looseObjectRestSpread = true,
5249
looseParameters = true,
5350
looseTemplateLiterals = true,
54-
typescript = false,
55-
react = false,
51+
modules = "auto",
5652
polyfillRegenerator = false,
53+
react = false,
54+
removePropTypes: removePropertyTypes = false,
55+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
56+
targets,
57+
typescript = false,
5758
useBuiltIns = false,
58-
corejs = false,
5959
} = options;
6060

6161
if (typeof modules === "boolean" && typeof modules === "string") {
@@ -103,15 +103,15 @@ const preset = declare((api: BabelAPI, options: Options): Record<string, any> =>
103103
[
104104
"@babel/preset-env",
105105
{
106-
debug,
107106
bugfixes: true,
108-
useBuiltIns,
107+
debug,
109108
exclude: ["transform-async-to-generator", "transform-regenerator"],
109+
loose,
110110
modules: modules === false ? false : "auto",
111+
shippedProposals: api.env("modern"),
111112
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
112113
targets,
113-
shippedProposals: api.env("modern"),
114-
loose,
114+
useBuiltIns,
115115
},
116116
],
117117
typescript
@@ -191,8 +191,8 @@ const preset = declare((api: BabelAPI, options: Options): Record<string, any> =>
191191
? [
192192
"babel-plugin-transform-react-remove-prop-types",
193193
{
194-
mode: "unsafe-wrap",
195194
ignoreFilenames: ["node_modules"],
195+
mode: "unsafe-wrap",
196196
...(removePropertyTypes as object),
197197
},
198198
]
@@ -227,8 +227,8 @@ const preset = declare((api: BabelAPI, options: Options): Record<string, any> =>
227227
? [
228228
"babel-plugin-polyfill-corejs3",
229229
{
230-
method: corejs.method ?? "usage-global",
231230
absoluteImports: "core-js",
231+
method: corejs.method ?? "usage-global",
232232
version: corejs.version,
233233
...corejs,
234234
},
@@ -240,8 +240,8 @@ const preset = declare((api: BabelAPI, options: Options): Record<string, any> =>
240240
assumptions: {
241241
noDocumentAll: true,
242242
},
243-
presets,
244243
plugins,
244+
presets,
245245
};
246246
});
247247

‎packages/babel-preset/src/postinstall.ts

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const writeBabelRc = () => {
2222
};
2323
`;
2424

25+
// eslint-disable-next-line security/detect-non-literal-fs-filename
2526
if (existsSync(babelPath)) {
2627
console.warn(`⚠️ babel.config.js already exists;
2728
Make sure that it includes the following for @anolilab/babel-preset'

‎packages/browserslist-config-anolilab/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const config = {
2-
production: ["> 1%", "last 2 versions", "Firefox ESR", "not dead"],
32
legacyBrowsers: ["> 1%", "last 2 versions", "Firefox ESR"],
43
modernBrowsers: [
54
"last 2 Chrome versions",
@@ -13,9 +12,10 @@ const config = {
1312
"last 2 Edge versions",
1413
"not Edge < 15",
1514
],
16-
ssr: ["node 16"],
1715
/** NOTE: Meaning LTS version. Any version above LTS is not considered as "major release", AFAIK. */
1816
node: ["last 2 node major versions"],
17+
production: ["> 1%", "last 2 versions", "Firefox ESR", "not dead"],
18+
ssr: ["node 16"],
1919
};
2020

2121
export default config;

‎packages/commitlint-config/src/postinstall.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ console.log("Configuring @anolilab/commitlint-config", projectPath, "\n");
1818
const writeCommitLintConfig = () => {
1919
const commitlintPath = join(projectPath, "commitlint.config.js");
2020

21+
// eslint-disable-next-line security/detect-non-literal-fs-filename
2122
if (existsSync(commitlintPath)) {
2223
console.warn("⚠️ commitlint.config.js already exists;");
2324

@@ -43,6 +44,7 @@ const writeCommitLintConfig = () => {
4344
const writeCzrc = () => {
4445
const filePath = join(projectPath, ".czrc");
4546

47+
// eslint-disable-next-line security/detect-non-literal-fs-filename
4648
if (existsSync(filePath)) {
4749
console.warn("⚠️ .czrc already exists;");
4850

‎packages/lint-staged-config/src/config.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,38 @@ type Groups = {
1818

1919
const groups: Groups = [
2020
{
21-
configName: "eslint",
2221
config: eslintConfig,
22+
configName: "eslint",
2323
dependencies: ["prettier", "eslint"],
2424
},
2525
{
26-
configName: "json",
2726
config: jsonConfig,
27+
configName: "json",
2828
dependencies: ["prettier", "sort-package-json"],
2929
},
3030
{
31-
configName: "markdown",
3231
config: markdownConfig,
32+
configName: "markdown",
3333
dependencies: ["prettier", "markdownlint-cli", "markdownlint-cli2"],
3434
},
3535
{
36-
configName: "secretlint",
3736
config: secretlintConfig,
37+
configName: "secretlint",
3838
dependencies: ["secretlint"],
3939
},
4040
{
41-
configName: "stylesheets",
4241
config: stylesheetsConfig,
42+
configName: "stylesheets",
4343
dependencies: ["stylelint"],
4444
},
4545
{
46-
configName: "tests",
4746
config: testsConfig,
47+
configName: "tests",
4848
dependencies: ["vite", "jest", "ava"],
4949
},
5050
{
51-
configName: "typescript",
5251
config: typescriptConfig,
52+
configName: "typescript",
5353
dependencies: ["typescript"],
5454
},
5555
];
@@ -60,8 +60,9 @@ const loadedPluginsNames: string[] = [];
6060
const possiblePlugins: { [rule: string]: { [packageName: string]: boolean } } = {};
6161

6262
groups.forEach((plugin) => {
63-
const { dependencies, config, configName } = plugin;
63+
const { config, configName, dependencies } = plugin;
6464

65+
// eslint-disable-next-line security/detect-object-injection
6566
if ((anolilabLintStagedConfig as unknown as { [key: string]: { [key: string]: false | undefined } })?.["plugin"]?.[configName] !== false) {
6667
const foundDependencies = [];
6768

@@ -75,9 +76,11 @@ groups.forEach((plugin) => {
7576
loadedPlugins = { ...loadedPlugins, ...config };
7677
loadedPluginsNames.push(configName);
7778
} else {
79+
// eslint-disable-next-line security/detect-object-injection
7880
possiblePlugins[configName] = {};
7981

8082
dependencies.forEach((dependency) => {
83+
// eslint-disable-next-line security/detect-object-injection
8184
(possiblePlugins[configName] as { [key: string]: boolean })[dependency] = hasDependency(dependency) || hasDevDependency(dependency);
8285
});
8386
}

‎packages/lint-staged-config/src/groups/eslint/group-file-paths-by-directory-name.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const groupFilePathsByDirectoryName = (filePaths: string[]): { [key: string]: st
66
filePaths.forEach((filePath) => {
77
const directoryName = dirname(filePath);
88

9+
// eslint-disable-next-line security/detect-object-injection
910
if (!groups[directoryName]) {
11+
// eslint-disable-next-line security/detect-object-injection
1012
groups[directoryName] = [];
1113
}
12-
14+
// eslint-disable-next-line security/detect-object-injection
1315
(groups[directoryName] as string[]).push(filePath);
1416
});
1517

‎packages/lint-staged-config/src/groups/eslint/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ if (!global.hasAnolilabLintStagedMarkdownCli && !global.hasAnolilabLintStagedMar
1919
}
2020

2121
const group: Config = {
22+
[`*.{${["json", "json5", "jsonc"].join(",")}}`]: async (filenames: string[]) => [...(await createEslintCommands(filenames))],
2223
[`*.{${[extensions].join(",")}}`]: async (filenames: string[]) => [
2324
`prettier --write ${concatFiles(filenames)}`,
2425
...(await createEslintCommands(filenames)),
2526
],
26-
[`*.{${["json", "json5", "jsonc"].join(",")}}`]: async (filenames: string[]) => [...(await createEslintCommands(filenames))],
2727
};
2828

2929
export default group;

‎packages/lint-staged-config/src/groups/eslint/remove-ignored-files.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const removeIgnoredFiles = async (filenames: string[]): Promise<string[]> => {
88
const eslint = new ESLint();
99
// eslint-disable-next-line compat/compat
1010
const ignoredFiles = await Promise.all(filenames.map((filename) => eslint.isPathIgnored(filename)));
11+
// eslint-disable-next-line security/detect-object-injection
1112
const filteredFiles = filenames.filter((_, index) => !ignoredFiles[index]);
1213

1314
return filteredFiles.map((filename) => `"${isWindows ? filename : quote([filename])}"`);

‎packages/lint-staged-config/src/groups/tests.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ const hasJest = hasDependency("jest") || hasDevDependency("jest");
88
const hasAva = hasDependency("ava") || hasDevDependency("ava");
99

1010
const group: Config = {
11-
...(hasVitest && { "**/__tests__/**/*.?(c|m)[jt]s?(x)": ["vitest related --run"], "**/?(*.){test,spec}.?(c|m)[jt]s?(x)": ["vitest related --run"] }),
11+
...(hasVitest && { "**/?(*.){test,spec}.?(c|m)[jt]s?(x)": ["vitest related --run"], "**/__tests__/**/*.?(c|m)[jt]s?(x)": ["vitest related --run"] }),
1212
...(hasJest && {
1313
"**/*.spec.{js,ts,tsx}": ["jest --findRelatedTests"],
1414
"**/*.test.{js,ts,tsx}": ["jest --findRelatedTests"],
15-
"**/test/*.{js,ts,tsx}": ["jest --findRelatedTests"],
15+
"**/?(*.){test,spec}.?(c|m)[jt]s?(x)": ["jest --findRelatedTests"],
1616
"**/__mocks__/*.{js,ts,tsx}": ["jest --findRelatedTests"],
17-
"**/__tests__/*.{js,ts,tsx}": ["jest --findRelatedTests"],
1817
"**/__tests__/**/*.?(c|m)[jt]s?(x)": ["jest --findRelatedTests"],
19-
"**/?(*.){test,spec}.?(c|m)[jt]s?(x)": ["jest --findRelatedTests"],
18+
"**/__tests__/*.{js,ts,tsx}": ["jest --findRelatedTests"],
19+
"**/test/*.{js,ts,tsx}": ["jest --findRelatedTests"],
2020
}),
2121
...(hasAva && {
22+
"**/(test|tests|__tests__)/**/*.js": (filenames: string[]) => [`ava ${concatFiles(filenames)}`],
23+
"**/*.(spec|test).js": (filenames: string[]) => [`ava ${concatFiles(filenames)}`],
2224
"**/test.js": (filenames: string[]) => [`ava ${concatFiles(filenames)}`],
2325
"**/test-*.js": (filenames: string[]) => [`ava ${concatFiles(filenames)}`],
24-
"**/*.(spec|test).js": (filenames: string[]) => [`ava ${concatFiles(filenames)}`],
25-
"**/(test|tests|__tests__)/**/*.js": (filenames: string[]) => [`ava ${concatFiles(filenames)}`],
2626
}),
2727
};
2828

‎packages/lint-staged-config/src/postinstall.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import {
2-
hasDependency, hasDevDependency, packageIsTypeModule, projectPath
3-
} from "@anolilab/package-json-utils";
1+
import { hasDependency, hasDevDependency, packageIsTypeModule, projectPath } from "@anolilab/package-json-utils";
42
import { existsSync, mkdir, writeFile } from "node:fs";
53
import { join } from "node:path";
4+
import { exit } from "node:process";
65
import { promisify } from "node:util";
76

87
import getNearestConfigPath from "./utils/get-nearest-config-path";
98

109
if (process.env["CI"]) {
11-
// eslint-disable-next-line unicorn/no-process-exit
12-
process.exit(0);
10+
exit(0);
1311
}
1412

1513
const writeFileAsync = promisify(writeFile);
@@ -20,6 +18,7 @@ console.log("Configuring @anolilab/lint-staged-config", projectPath, "\n");
2018
const configFile = ".lintstagedrc";
2119

2220
const checkIfFileExists = (filename: string): boolean => {
21+
// eslint-disable-next-line security/detect-non-literal-fs-filename
2322
if (existsSync(filename)) {
2423
console.warn(`⚠️ ${filename} already exists;`);
2524

@@ -78,6 +77,7 @@ const writeHuskyFiles = async () => {
7877

7978
const huskyFolderPath = join(projectPath, ".husky");
8079

80+
// eslint-disable-next-line security/detect-non-literal-fs-filename
8181
if (!existsSync(huskyFolderPath)) {
8282
await mkdirAsync(huskyFolderPath);
8383
}
@@ -209,13 +209,11 @@ echo --------------------------------------------
209209

210210
console.log("😎 Everything went well, have fun!");
211211

212-
// eslint-disable-next-line unicorn/no-process-exit
213-
process.exit(0);
212+
exit(0);
214213
} catch (error) {
215214
console.log("😬 something went wrong:");
216215
console.error(error);
217216

218-
// eslint-disable-next-line unicorn/no-process-exit
219-
process.exit(1);
217+
exit(1);
220218
}
221219
})();

‎packages/lint-staged-config/src/utils/get-nearest-config-path.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const getNearestConfigPath = <N extends ConfigFileName, A extends AbsolutePath =
3333
const packageRootPath = getNearestPackageRootPath(cwd);
3434
const configPath = joinPaths<[A, N]>([packageRootPath as A, fileName]);
3535

36+
// eslint-disable-next-line security/detect-non-literal-fs-filename
3637
if (existsSync(configPath)) {
3738
return configPath;
3839
}

‎packages/lint-staged-config/src/utils/logger.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { env } from "node:process";
22

33
const noop = () => undefined;
44

5-
const consolePrefix = (prefix: string) =>
6-
// eslint-disable-next-line implicit-arrow-linebreak
7-
(env["NO_LOGS"] ? noop : (message: string) => console.log(`${prefix}${message}`));
5+
const consolePrefix = (prefix: string) => (env["NO_LOGS"] ? noop : (message: string) => console.log(`${prefix}${message}`));
86

97
const consoleLog = consolePrefix("");
108

‎packages/package-json-utils/__tests__/index.test.ts

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { dirname } from "node:path";
2-
import {
3-
describe, expect, it, vi,
4-
} from "vitest";
2+
import { describe, expect, it, vi } from "vitest";
53

64
import {
75
environmentIsSet,
8-
fromRoot, getPackageProperty, getPackageSubProperty,
6+
fromRoot,
7+
getPackageProperty,
8+
getPackageSubProperty,
99
hasAnyDep,
1010
hasDep,
1111
hasDevelopmentDep,
@@ -124,27 +124,30 @@ describe("package-json-utils", () => {
124124
expect(isPackageAvailable("vitest2")).toBeFalsy();
125125
});
126126

127-
it.each<"error" | "info" | "log" | "warn">(["warn", "log", "error", "info"])("showMissingPackages: logs a %type message with the missing packages", (type) => {
128-
const consoleMock = vi.spyOn(console, type);
127+
it.each<"error" | "info" | "log" | "warn">(["warn", "log", "error", "info"])(
128+
"showMissingPackages: logs a %type message with the missing packages",
129+
(type) => {
130+
const consoleMock = vi.spyOn(console, type);
129131

130-
showMissingPackages("example", ["package1", "package2"], {
131-
consoleType: type,
132-
});
132+
showMissingPackages("example", ["package1", "package2"], {
133+
consoleType: type,
134+
});
133135

134-
expect(consoleMock).toHaveBeenCalledTimes(1);
135-
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining("example could not find the following packages"));
136-
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining("package1"));
137-
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining("package2"));
136+
expect(consoleMock).toHaveBeenCalledTimes(1);
137+
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining("example could not find the following packages"));
138+
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining("package1"));
139+
expect(consoleMock).toHaveBeenCalledWith(expect.stringContaining("package2"));
138140

139-
consoleMock.mockRestore();
140-
});
141+
consoleMock.mockRestore();
142+
},
143+
);
141144

142145
it("showMissingPackages: logs a warning message with the missing packages, pre and post message", () => {
143146
const consoleMock = vi.spyOn(console, "warn");
144147

145148
showMissingPackages("example", ["package1", "package2"], {
146-
preMessage: "pre message",
147149
postMessage: "post message",
150+
preMessage: "pre message",
148151
});
149152

150153
expect(consoleMock).toHaveBeenCalledTimes(1);

‎packages/package-json-utils/src/index.ts

+27-12
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { getByPath } from "dot-path-value";
22
import { existsSync, realpathSync } from "node:fs";
33
import module from "node:module";
44
import { dirname, join } from "node:path";
5+
import { cwd, env, exit, versions } from "node:process";
56
import type { NormalizedPackageJson } from "read-pkg";
67
import readPkgUp from "read-pkg-up";
78

89
const { packageJson, path: packagePath } = readPkgUp.sync({
9-
cwd: realpathSync(process.cwd()),
10+
// eslint-disable-next-line security/detect-non-literal-fs-filename
11+
cwd: realpathSync(cwd()),
1012
}) ?? { packageJson: undefined, path: undefined };
1113

1214
const atLatest = (name: string): string => {
@@ -25,11 +27,17 @@ export const getPackageProperty = <T = unknown>(property: string): T | undefined
2527
return getByPath(packageJson, property) as T | undefined;
2628
};
2729

28-
export const getPackageSubProperty = <T = unknown>(packageProperty: string) => (property: string): T | undefined => getPackageProperty<T>(`${packageProperty}.${property}`);
30+
export const getPackageSubProperty =
31+
<T = unknown>(packageProperty: string) =>
32+
(property: string): T | undefined =>
33+
getPackageProperty<T>(`${packageProperty}.${property}`);
2934

3035
export const hasPackageProperty = (property: string): boolean => Boolean(packageJson !== undefined && getByPath(packageJson, property));
3136

32-
export const hasPackageSubProperty = (packageProperty: string) => (property: string): boolean => hasPackageProperty(`${packageProperty}.${property}`);
37+
export const hasPackageSubProperty =
38+
(packageProperty: string) =>
39+
(property: string): boolean =>
40+
hasPackageProperty(`${packageProperty}.${property}`);
3341

3442
export const hasPackageProperties = (properties: string[], strict?: boolean): boolean => {
3543
if (strict) {
@@ -39,19 +47,25 @@ export const hasPackageProperties = (properties: string[], strict?: boolean): bo
3947
return properties.some((property: string) => hasPackageProperty(property));
4048
};
4149

42-
export const hasPackageSubProperties = (packageProperty: string) => (properties: string[], strict?: boolean): boolean => hasPackageProperties(
50+
export const hasPackageSubProperties =
51+
(packageProperty: string) =>
52+
(properties: string[], strict?: boolean): boolean =>
53+
hasPackageProperties(
4354
properties.map((p) => `${packageProperty}.${p}`),
4455
strict,
4556
);
4657

47-
export const environmentIsSet = (name: string): boolean => Boolean(process.env[name] && process.env[name] !== "undefined");
58+
// eslint-disable-next-line security/detect-object-injection
59+
export const environmentIsSet = (name: string): boolean => Boolean(env[name] && env[name] !== "undefined");
4860

4961
export const parseEnvironment = (name: string, defaultValue: unknown): any => {
5062
if (environmentIsSet(name)) {
5163
try {
52-
return JSON.parse(process.env[name] ?? "");
64+
// eslint-disable-next-line security/detect-object-injection
65+
return JSON.parse(env[name] ?? "");
5366
} catch {
54-
return process.env[name];
67+
// eslint-disable-next-line security/detect-object-injection
68+
return env[name];
5569
}
5670
}
5771

@@ -62,6 +76,7 @@ export const projectPath: string = packagePath ? dirname(packagePath) : "";
6276
// @deprecated Use `projectPath` instead.
6377
export const appDirectory: string = projectPath;
6478
export const fromRoot = (...p: string[]): string => join(projectPath, ...p);
79+
// eslint-disable-next-line security/detect-non-literal-fs-filename
6580
export const hasFile = (...p: string[]): boolean => existsSync(fromRoot(...p));
6681

6782
export const hasScripts = hasPackageSubProperties("scripts");
@@ -80,8 +95,8 @@ export const hasDevDependencies = hasPackageSubProperties("devDependencies");
8095
// @deprecated Use `hasDevDependencies` instead.
8196
export const hasDevelopmentDep = hasDevDependencies;
8297

83-
// eslint-disable-next-line max-len
84-
export const hasAnyDep = (arguments_: string[], options?: { peerDeps?: boolean; strict?: boolean }): boolean => [hasDependencies, hasDevDependencies, options?.peerDeps === false ? () => false : hasPeerDependencies].some(
98+
export const hasAnyDep = (arguments_: string[], options?: { peerDeps?: boolean; strict?: boolean }): boolean =>
99+
[hasDependencies, hasDevDependencies, options?.peerDeps === false ? () => false : hasPeerDependencies].some(
85100
(function_: (arguments_: string[], strict?: boolean) => boolean) => function_(arguments_, options?.strict),
86101
);
87102

@@ -91,7 +106,7 @@ export const packageIsTypeModule = hasPackageProperties(["type"]) && packageJson
91106

92107
export const resolvePackage = (packageName: string): string | undefined => {
93108
// See https://yarnpkg.com/advanced/pnpapi
94-
if (process.versions["pnp"]) {
109+
if (versions["pnp"]) {
95110
const targetModule = import.meta.url;
96111
// @ts-expect-error TS2339: Property 'findPnpApi' does not exist on type 'typeof Module'.
97112
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
@@ -158,8 +173,8 @@ or
158173
${options.postMessage ?? ""}\n
159174
`);
160175

161-
if (process.env["NODE_ENV"] !== "test" || options.exit === true) {
162-
process.exit(1); // eslint-disable-line unicorn/no-process-exit
176+
if (env["NODE_ENV"] !== "test" || options.exit === true) {
177+
exit(1);
163178
}
164179
};
165180

‎packages/prettier-config/src/index.ts

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,20 @@
11
import type { Config } from "prettier";
22

33
const config: Config = {
4-
// max 160 characters per line
5-
printWidth: 160,
6-
// use 4 spaces for indentation
7-
tabWidth: 4,
8-
// use spaces instead of indentations
9-
useTabs: false,
10-
// semicolon at the end of the line
11-
semi: true,
12-
// use single quotes
13-
singleQuote: false,
14-
// object's key is quoted only when necessary
15-
quoteProps: "as-needed",
16-
// use double quotes instead of single quotes in jsx
17-
jsxSingleQuote: false,
18-
// all comma at the end
19-
trailingComma: "all",
20-
// spaces are required at the beginning and end of the braces
21-
bracketSpacing: true,
224
// brackets are required for arrow function parameter, even when there is only one parameter
235
arrowParens: "always",
24-
// format the entire contents of the file
25-
rangeStart: 0,
26-
rangeEnd: Number.POSITIVE_INFINITY,
27-
// no need to write the beginning @prettier of the file
28-
requirePragma: false,
29-
// No need to automatically insert @prettier at the beginning of the file
30-
insertPragma: false,
31-
// use default break criteria
32-
proseWrap: "preserve",
33-
// decide whether to break the html according to the display style
34-
htmlWhitespaceSensitivity: "css",
35-
// vue files script and style tags indentation
36-
vueIndentScriptAndStyle: false,
37-
// lf for newline
38-
endOfLine: "lf",
6+
// spaces are required at the beginning and end of the braces
7+
bracketSpacing: true,
398
// formats quoted code embedded
409
embeddedLanguageFormatting: "auto",
10+
// lf for newline
11+
endOfLine: "lf",
12+
// decide whether to break the html according to the display style
13+
htmlWhitespaceSensitivity: "css",
14+
// No need to automatically insert @prettier at the beginning of the file
15+
insertPragma: false,
16+
// use double quotes instead of single quotes in jsx
17+
jsxSingleQuote: false,
4118
overrides: [
4219
{ files: ".eslintrc", options: { parser: "json" } },
4320
{ files: ".prettierrc", options: { parser: "json" } },
@@ -46,6 +23,29 @@ const config: Config = {
4623
{ files: "*.yml", options: { singleQuote: false } },
4724
{ files: "*.yaml", options: { singleQuote: false } },
4825
],
26+
// max 160 characters per line
27+
printWidth: 160,
28+
// use default break criteria
29+
proseWrap: "preserve",
30+
// object's key is quoted only when necessary
31+
quoteProps: "as-needed",
32+
rangeEnd: Number.POSITIVE_INFINITY,
33+
// format the entire contents of the file
34+
rangeStart: 0,
35+
// no need to write the beginning @prettier of the file
36+
requirePragma: false,
37+
// semicolon at the end of the line
38+
semi: true,
39+
// use single quotes
40+
singleQuote: false,
41+
// use 4 spaces for indentation
42+
tabWidth: 4,
43+
// all comma at the end
44+
trailingComma: "all",
45+
// use spaces instead of indentations
46+
useTabs: false,
47+
// vue files script and style tags indentation
48+
vueIndentScriptAndStyle: false,
4949
};
5050

5151
export default config;

‎packages/prettier-config/src/postinstall.ts

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const writePrettierRc = () => {
3333
"prettier.config.js",
3434
"prettier.config.cjs",
3535
]) {
36+
// eslint-disable-next-line security/detect-non-literal-fs-filename
3637
if (existsSync(join(projectPath, filename))) {
3738
console.warn(`⚠️ ${filename} already exists;
3839
Make sure that it includes the following for @anolilab/prettier-config to work as it should:
@@ -62,6 +63,7 @@ ${packageIsTypeModule ? "export default" : "module.exports ="} {
6263
const writePrettierIgnore = () => {
6364
const prettierPath = join(projectPath, ".prettierignore");
6465

66+
// eslint-disable-next-line security/detect-non-literal-fs-filename
6567
if (existsSync(prettierPath)) {
6668
console.warn("⚠️ .prettierignore already exists");
6769

‎packages/semantic-release-preset/src/postinstall.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import {
2-
hasDep, hasDevelopmentDep, pkg, projectPath
3-
} from "@anolilab/package-json-utils";
1+
import { hasDep, hasDevelopmentDep, pkg, projectPath } from "@anolilab/package-json-utils";
42
import { existsSync, writeFile } from "node:fs";
53
import { join } from "node:path";
64
import { promisify } from "node:util";
@@ -19,8 +17,8 @@ console.log("Configuring @anolilab/semantic-release-preset", projectPath, "\n");
1917
*/
2018
const writeReleaseRc = () => {
2119
if (
22-
pkg
23-
&& (hasDevelopmentDep(["multi-semantic-release", "@qiwi/multi-semantic-release"]) || hasDep(["multi-semantic-release", "@qiwi/multi-semantic-release"]))
20+
pkg &&
21+
(hasDevelopmentDep(["multi-semantic-release", "@qiwi/multi-semantic-release"]) || hasDep(["multi-semantic-release", "@qiwi/multi-semantic-release"]))
2422
) {
2523
console.warn("⚠️ found use of multi-semantic-release;");
2624

@@ -29,6 +27,7 @@ const writeReleaseRc = () => {
2927

3028
const releaseRcPath = join(projectPath, ".releaserc.json");
3129

30+
// eslint-disable-next-line security/detect-non-literal-fs-filename
3231
if (existsSync(releaseRcPath)) {
3332
console.warn("⚠️ .releaserc.json already exists;");
3433

‎packages/stylelint-config/src/config/tailwindcss.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ const config = {
1717
],
1818
},
1919
],
20+
"declaration-block-trailing-semicolon": null,
2021
"function-no-unknown": [
2122
true,
2223
{
2324
ignoreFunctions: ["theme"],
2425
},
2526
],
26-
"declaration-block-trailing-semicolon": null,
2727
"no-descending-specificity": null,
2828
},
2929
};

‎packages/stylelint-config/src/postinstall.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const file = ".stylelintrc";
2020
const writeStylelintRc = () => {
2121
// eslint-disable-next-line no-restricted-syntax
2222
for (const filename of [file, `${file}.js`, `${file}.cjs`, `${file}.json`, `${file}.yaml`, `${file}.yml`, `stylelint.config.js`, `stylelint.config.cjs`]) {
23+
// eslint-disable-next-line security/detect-non-literal-fs-filename
2324
if (existsSync(join(projectPath, filename))) {
2425
console.warn(
2526
'⚠️ .stylelintrc.js already exists; Make sure that it includes the following for @anolilab/stylelint-config to work as it should: { "extends": ["@anolilab/stylelint-config"] }.',
@@ -55,7 +56,7 @@ node_modules/**
5556
.next/**
5657
5758
`;
58-
59+
// eslint-disable-next-line security/detect-non-literal-fs-filename
5960
if (existsSync(stylelintIgnorePath)) {
6061
return Promise.resolve();
6162
}

‎packages/textlint-config/src/postinstall.ts

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ const writeTextLintRc = () => {
155155
}
156156
`;
157157

158+
// eslint-disable-next-line security/detect-non-literal-fs-filename
158159
if (existsSync(filePath)) {
159160
console.warn(`⚠️ .textlintrc already exists;
160161
Make sure that it includes the following for @anolilab/textlint-config'
@@ -173,6 +174,7 @@ const writeTextLintIgnore = () => {
173174
const filePath = join(projectPath, ".textlintignore");
174175
const content = "";
175176

177+
// eslint-disable-next-line security/detect-non-literal-fs-filename
176178
if (existsSync(filePath)) {
177179
console.warn("⚠️ .textlintignore already exists;");
178180

0 commit comments

Comments
 (0)
Please sign in to comment.