Skip to content

Commit

Permalink
chore: enable no-implicit-any on review-dependencies.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Nov 4, 2024
1 parent 01e2f25 commit bfeebc9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
12 changes: 10 additions & 2 deletions lib/new-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,18 @@ async function addRule(options, elmJson, ruleName, ruleType) {

if (elmJson.type === 'package' && packageNameRegex.test(elmJson.name)) {
console.log('Exposing the rule in elm.json');
if (!elmJson['exposed-modules'].includes(ruleName)) {

const exposedModules = Array.isArray(elmJson['exposed-modules'])
? elmJson['exposed-modules']
: Object.values(elmJson['exposed-modules']).reduce((acc, items) => [
...acc,
...items
]);

if (!exposedModules.includes(ruleName)) {
const newElmJson = {
...elmJson,
'exposed-modules': [...elmJson['exposed-modules'], ruleName].sort()
'exposed-modules': [...exposedModules, ruleName].sort()
};

writeFile(dir, 'elm.json', JSON.stringify(newElmJson, null, 4));
Expand Down
28 changes: 25 additions & 3 deletions lib/review-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/**
* @import {ApplicationDependencyList, PackageElmJson, PackageName} from './types/content';
* @import {VersionString} from './types/version';
*/

const ProjectJsonFiles = require('./project-json-files');

/**
* @param {ApplicationDependencyList} reviewDirectDependencies
* @param {VersionString} elmVersion
*/
async function collectRuleLinks(reviewDirectDependencies, elmVersion) {
const elmJsonForReviewDependenciesPromises = Object.entries(
reviewDirectDependencies
Expand All @@ -24,6 +33,10 @@ async function collectRuleLinks(reviewDirectDependencies, elmVersion) {
);
}

/**
* @param {ApplicationDependencyList} reviewDirectDependencies
* @param {PackageElmJson[]} elmJsonForReviewDependencies
*/
function computeLinksToRuleDocs(
reviewDirectDependencies,
elmJsonForReviewDependencies
Expand All @@ -42,19 +55,28 @@ function computeLinksToRuleDocs(
? dep['exposed-modules']
: Object.values(dep['exposed-modules']).reduce((acc, items) => [
...acc,
items
...items
]);

for (const moduleName of exposedModules) {
acc[moduleName] = linkToModule(depName, packageVersion, moduleName);
acc[moduleName] = linkToModule(
/** @type {PackageName} */ (depName),
packageVersion,
moduleName
);
}

return acc;
},
{}
/** @type {Record<string, string>} */ ({})
);
}

/**
* @param {PackageName} dependencyName
* @param {VersionString} packageVersion
* @param {string} moduleName
*/
function linkToModule(dependencyName, packageVersion, moduleName) {
const urlModuleName = moduleName.split('.').join('-');
return `https://package.elm-lang.org/packages/${dependencyName}/${packageVersion}/${urlModuleName}`;
Expand Down
2 changes: 1 addition & 1 deletion lib/types/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type PackageElmJson = {
summary: string;
license: string;
version: VersionString;
'exposed-modules': (string | Record<string, string>)[];
'exposed-modules': string[] | Record<string, string[]>;
'elm-version': VersionRange;
dependencies: PackageDependencyList;
'test-dependencies': PackageDependencyList;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.no-implicit-any.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"lib/result-cache.js",
"lib/result-cache-json.js",
"lib/result-cache-worker.js",
"lib/review-dependencies.js",
"lib/spinner.js",
"lib/state.js",
"lib/styled-message.js",
Expand Down

0 comments on commit bfeebc9

Please sign in to comment.