Skip to content

Commit 7b03938

Browse files
committedApr 8, 2024·
fix noForEach and noCatchAssign
1 parent a427dd8 commit 7b03938

22 files changed

+84
-72
lines changed
 

‎biome.json

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"rules": {
2222
"recommended": true,
2323
"complexity": {
24-
"noForEach": "off",
2524
"useLiteralKeys": "off"
2625
},
2726
"style": {
@@ -30,7 +29,6 @@
3029
"useTemplate": "off"
3130
},
3231
"suspicious": {
33-
"noCatchAssign": "off",
3432
"noExplicitAny": "off",
3533
"noPrototypeBuiltins": "off"
3634
}

‎src/cli/domain/handle-dependencies/get-missing-dependencies.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export default function getMissingDependencies(
66
): string[] {
77
const missing: string[] = [];
88

9-
Object.entries(dependencies).forEach(([dependency, version]) => {
9+
for (const [dependency, version] of Object.entries(dependencies)) {
1010
const pathToModule = path.resolve('node_modules/', dependency);
1111
if (!moduleExists(pathToModule)) {
1212
missing.push(`${dependency}@${version || 'latest'}`);
1313
}
14-
});
14+
}
1515

1616
return missing;
1717
}

‎src/cli/domain/handle-dependencies/index.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ export default async function handleDependencies(options: {
2929
const { components, logger, useComponentDependencies } = options;
3030

3131
const dependencies: Record<string, string> = {};
32-
const addDependencies = (componentDependencies?: Record<string, string>) =>
33-
Object.entries(componentDependencies || {}).forEach(
34-
([dependency, version]) => {
35-
dependencies[dependency] = version;
36-
}
37-
);
32+
const addDependencies = (componentDependencies?: Record<string, string>) => {
33+
for (const [dependency, version] of Object.entries(
34+
componentDependencies || {}
35+
)) {
36+
dependencies[dependency] = version;
37+
}
38+
};
3839

3940
const templates: Record<string, Template> = {};
4041
const addTemplate = (templateName: string, template: Template) => {

‎src/cli/domain/handle-dependencies/require-template.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ export default function requireTemplate(
4848
template
4949
);
5050

51-
[componentRelativePath, template, localTemplate, relativeTemplate].forEach(
52-
(pathToTry) => {
53-
ocTemplate = ocTemplate || cleanRequire(pathToTry, { justTry: true });
54-
}
55-
);
51+
for (const pathToTry of [
52+
componentRelativePath,
53+
template,
54+
localTemplate,
55+
relativeTemplate
56+
]) {
57+
ocTemplate = ocTemplate || cleanRequire(pathToTry, { justTry: true });
58+
}
5659

5760
if (!ocTemplate) {
5861
throw new Error(strings.errors.cli.TEMPLATE_NOT_FOUND(template));

‎src/cli/facade/dev.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) =>
108108

109109
const registerPlugins = (registry: Registry) => {
110110
const mockedPlugins = getMockedPlugins(logger, componentsDir);
111-
mockedPlugins.forEach((p) => registry.register(p));
111+
for (const plugin of mockedPlugins) {
112+
registry.register(plugin);
113+
}
112114

113115
registry.on('request', (data) => {
114116
if (data.errorCode === 'PLUGIN_MISSING_FROM_REGISTRY') {
@@ -135,10 +137,9 @@ const dev = ({ local, logger }: { logger: Logger; local: Local }) =>
135137
}
136138

137139
logger.ok('OK');
138-
components.forEach((component) =>
139-
logger.log(colors.green('├── ') + component)
140-
);
141-
140+
for (const component of components) {
141+
logger.log(colors.green('├── ') + component);
142+
}
142143
const dependencies = await handleDependencies({
143144
components,
144145
logger

‎src/cli/facade/publish.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,16 @@ const publish = ({
133133
} else {
134134
if (err.message) {
135135
// eslint-disable-next-line no-ex-assign
136-
err = err.message;
136+
errorMessage = err.message;
137137
} else if (err && typeof err === 'object') {
138138
try {
139139
// eslint-disable-next-line no-ex-assign
140-
err = JSON.stringify(err);
140+
errorMessage = JSON.stringify(err);
141141
} catch (er) {}
142142
}
143-
errorMessage = strings.errors.cli.PUBLISHING_FAIL(String(err));
143+
errorMessage = strings.errors.cli.PUBLISHING_FAIL(
144+
String(errorMessage)
145+
);
144146
logger.err(errorMessage);
145147

146148
throw errorMessage;

‎src/cli/facade/registry-ls.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const registryLs = ({
2424
throw err;
2525
}
2626

27-
registries.forEach((registryLocation) => logger.ok(registryLocation));
27+
for (const registryLocation of registries) {
28+
logger.ok(registryLocation);
29+
}
2830

2931
return registries;
3032
} catch (err) {

‎src/cli/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ function processCommand(
123123
);
124124
}
125125

126-
Object.entries(commands.commands).forEach(([commandName, command]) => {
126+
for (const [commandName, command] of Object.entries(commands.commands)) {
127127
processCommand(command, commandName, cli);
128-
});
128+
}
129129

130130
const argv = cli
131131
.completion()

‎src/registry/domain/events-handler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ type EventsHandler = {
5656
const eventsHandler: EventsHandler = {
5757
fire(eventName: string, eventData: unknown): void {
5858
if (subscriptions[eventName]) {
59-
subscriptions[eventName].forEach((callback) => {
59+
for (const callback of subscriptions[eventName]) {
6060
callback(eventData);
61-
});
61+
}
6262
}
6363
},
6464

‎src/registry/domain/plugins-initialiser.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ function validatePlugins(plugins: unknown[]): asserts plugins is Plugin[] {
2727
function checkDependencies(plugins: Plugin[]) {
2828
const graph = new DepGraph();
2929

30-
plugins.forEach((p) => graph.addNode(p.name));
30+
for (const plugin of plugins) {
31+
graph.addNode(plugin.name);
32+
}
3133

32-
plugins.forEach((p) => {
34+
for (const p of plugins) {
3335
if (!p.register.dependencies) {
3436
return;
3537
}
3638

37-
p.register.dependencies.forEach((d) => {
39+
for (const d of p.register.dependencies) {
3840
try {
3941
graph.addDependency(p.name, d);
4042
} catch (err) {
4143
throw new Error(`unknown plugin dependency: ${d}`);
4244
}
43-
});
44-
});
45+
}
46+
}
4547

4648
return graph.overallOrder();
4749
}
@@ -64,11 +66,11 @@ export async function init(
6466
}
6567

6668
let present = true;
67-
dependencies.forEach((d) => {
69+
for (const d of dependencies) {
6870
if (!registered[d]) {
6971
present = false;
7072
}
71-
});
73+
}
7274

7375
return present;
7476
};

‎src/registry/router.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ export function create(app: Express, conf: Config, repository: Repository) {
7676
app.get(`${prefix}:componentName`, routes.component);
7777

7878
if (conf.routes) {
79-
conf.routes.forEach((route) =>
79+
for (const route of conf.routes) {
8080
app[
8181
route.method.toLowerCase() as 'get' | 'post' | 'put' | 'patch' | 'head'
82-
](route.route, route.handler)
83-
);
82+
](route.route, route.handler);
83+
}
8484
}
8585
}

‎src/registry/routes/helpers/apply-default-values.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ export default function applyDefaultValues(
1616
!params[1].mandatory && typeof params[1].default !== 'undefined'
1717
);
1818

19-
optionalParametersWithDefaults.forEach(
20-
([expectedParameterName, expectedParameter]) => {
21-
const param = requestParameters[expectedParameterName];
22-
if (param === null || param === undefined) {
23-
requestParameters[expectedParameterName] = expectedParameter.default;
24-
}
19+
for (const [
20+
expectedParameterName,
21+
expectedParameter
22+
] of optionalParametersWithDefaults) {
23+
const param = requestParameters[expectedParameterName];
24+
if (param === null || param === undefined) {
25+
requestParameters[expectedParameterName] = expectedParameter.default;
2526
}
26-
);
27+
}
2728

2829
return requestParameters;
2930
}

‎src/utils/put.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ async function put(
1414
files = [files];
1515
}
1616

17-
files.forEach((file) => {
17+
for (const file of files) {
1818
const fileName = path.basename(file);
1919
form.append(fileName, fs.createReadStream(file));
20-
});
20+
}
2121

2222
const res = await got(urlPath, {
2323
headers: { ...headers, ...form.getHeaders() },

‎tasks/changelog.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ module.exports = () =>
77
new Promise((resolve, reject) => {
88
const writeChangelog = (changelog, cb) => {
99
let result = '## Change Log';
10-
changelog.forEach((pr) => {
10+
for (const pr of changelog) {
1111
if (pr.changes.length > 0) {
1212
result += `\n\n### ${pr.tag.to}\n${pr.changes.join('\n')}`;
1313
}
14-
});
14+
}
1515
fs.writeFile(path.join(__dirname, '../CHANGELOG.md'), result, cb);
1616
};
1717

‎tasks/git.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const utils = {
77
formatPrs: (commits) => {
88
const result = [];
99

10-
commits.forEach((commit) => {
10+
for (const commit of commits) {
1111
const commitMessages = commit.message.split('Merge pull request');
1212
const isPr = commitMessages.length > 1;
1313
const isSquashedPr = !!commit.message.match(/(.*?)\(#(.*?)\)/g);
@@ -40,7 +40,7 @@ const utils = {
4040
`- [#${prNumber}](https://github.com/opencomponents/oc/pull/${prNumber}) ${commitMessage}`
4141
);
4242
}
43-
});
43+
}
4444

4545
return result;
4646
},

‎tasks/mochaTest.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ const packageComponent = (componentName, done) =>
3535

3636
const addTestSuite = (dir, done) =>
3737
glob(path.join(__dirname, '..', dir), (err, files) => {
38-
files.forEach((file) => mocha.addFile(file));
38+
for (const file of files) {
39+
mocha.addFile(file);
40+
}
3941
done();
4042
});
4143

‎test/unit/cli-domain-handle-dependencies-get-missing-dependencies.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('cli : domain : handle-dependencies - get-missing-dependencies', () =>
2121
}
2222
];
2323

24-
scenarios.forEach((scenario) => {
24+
for (const scenario of scenarios) {
2525
const { dependencies, installed, output } = scenario;
2626
describe(`When dependencies: ${JSON.stringify(
2727
dependencies
@@ -58,5 +58,5 @@ describe('cli : domain : handle-dependencies - get-missing-dependencies', () =>
5858
});
5959
});
6060
});
61-
});
61+
}
6262
});

‎test/unit/cli-programmatic-api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('cli : programmatic-api', () => {
5252
}
5353
];
5454

55-
scenarios.forEach((scenario) => {
55+
for (const scenario of scenarios) {
5656
describe(`cmd: cli.${scenario.cmd}`, () => {
5757
const fn = _.get(programmaticApi, scenario.cmd);
5858

@@ -68,5 +68,5 @@ describe('cli : programmatic-api', () => {
6868
.that.has.all.keys(scenario.dependencies);
6969
});
7070
});
71-
});
71+
}
7272
});

‎test/unit/cli-validate-command.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('cli : validate-command : valid', () => {
1717
}
1818
];
1919

20-
scenarios.forEach((scenario) => {
20+
for (const scenario of scenarios) {
2121
describe(`given "${scenario._.join(' ')}"`, () => {
2222
it(`"${scenario._[scenario.level]}" should be a valid command`, () => {
2323
const argv = {
@@ -28,7 +28,7 @@ describe('cli : validate-command : valid', () => {
2828
expect(validate(argv, level)).to.be.true;
2929
});
3030
});
31-
});
31+
}
3232
});
3333

3434
describe('cli : validate-command : invalid', () => {
@@ -43,7 +43,7 @@ describe('cli : validate-command : invalid', () => {
4343
}
4444
];
4545

46-
scenarios.forEach((scenario) => {
46+
for (const scenario of scenarios) {
4747
describe(`given "${scenario._.join(' ')}"`, () => {
4848
it(`"${scenario._[scenario.level]}" should be an invalid command`, () => {
4949
const argv = {
@@ -56,5 +56,5 @@ describe('cli : validate-command : invalid', () => {
5656
}).to.throw();
5757
});
5858
});
59-
});
59+
}
6060
});

‎test/unit/registry-domain-options-sanitiser.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ describe('registry : domain : options-sanitiser', () => {
1515
timeout: 120000
1616
};
1717

18-
Object.entries(defaults).forEach(([property, value]) => {
18+
for (const [property, value] of Object.entries(defaults)) {
1919
it(`should set ${property} to ${JSON.stringify(value)}`, () => {
2020
expect(sanitise(options)[property]).to.eql(value);
2121
});
22-
});
22+
}
2323
});
2424

2525
describe('when verbosity is provided', () => {
@@ -108,14 +108,14 @@ describe('registry : domain : options-sanitiser', () => {
108108
];
109109

110110
it('should support various scenarios correctly', () => {
111-
prefixAndBaseUrlScenarios.forEach((scenario) => {
111+
for (const scenario of prefixAndBaseUrlScenarios) {
112112
expect(sanitise(scenario.options).prefix).to.equal(
113113
scenario.expected.prefix
114114
);
115115
expect(sanitise(scenario.options).baseUrl).to.equal(
116116
scenario.expected.baseUrl
117117
);
118-
});
118+
}
119119
});
120120
});
121121

‎test/unit/registry-domain-validator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -908,11 +908,11 @@ describe('registry : domain : validator', () => {
908908
}
909909
];
910910

911-
scenarios.forEach((scenario) => {
911+
for (const scenario of scenarios) {
912912
it(`should be valid with mimetype ${scenario.mimetype}`, () => {
913913
expect(validate([scenario]).isValid).to.be.true;
914914
});
915-
});
915+
}
916916
});
917917
});
918918

‎test/unit/utils-npm-utils.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('utils : npm-utils', () => {
2727
}
2828
];
2929

30-
scenarios.forEach((scenario) => {
30+
for (const scenario of scenarios) {
3131
const { initPath, silent } = scenario.input;
3232
describe(`when invoked for ${initPath} with silent=${silent}`, () => {
3333
let error;
@@ -60,7 +60,7 @@ describe('utils : npm-utils', () => {
6060
expect(onStub.args[1][0]).to.equal('close');
6161
});
6262
});
63-
});
63+
}
6464
});
6565

6666
describe('installDependency()', () => {
@@ -115,7 +115,7 @@ describe('utils : npm-utils', () => {
115115
}
116116
];
117117

118-
scenarios.forEach((scenario) => {
118+
for (const scenario of scenarios) {
119119
const dependency = scenario.input.dependency;
120120
describe(`when invoked for installing ${dependency}`, () => {
121121
let error;
@@ -162,7 +162,7 @@ describe('utils : npm-utils', () => {
162162
expect(onStub.args[1][0]).to.equal('close');
163163
});
164164
});
165-
});
165+
}
166166
});
167167

168168
describe('installDependencies()', () => {
@@ -230,7 +230,7 @@ describe('utils : npm-utils', () => {
230230
}
231231
];
232232

233-
scenarios.forEach((scenario) => {
233+
for (const scenario of scenarios) {
234234
const dependencies = scenario.input.dependencies;
235235
describe(`when invoked for installing [${dependencies.join(
236236
', '
@@ -281,6 +281,6 @@ describe('utils : npm-utils', () => {
281281
expect(onStub.args[1][0]).to.equal('close');
282282
});
283283
});
284-
});
284+
}
285285
});
286286
});

0 commit comments

Comments
 (0)
Please sign in to comment.