Skip to content

Commit

Permalink
fix: regex match for keys rule (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored May 25, 2023
1 parent b1720d4 commit 4356c36
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/rules/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const validateKeys = (packageJson: PackageJson, packageJsonPath: string)
const dependencies = getDependencies(packageJson);
Object.keys(dependencies).forEach(dependency => {
const stringifiedPackageJson = readFileSync(packageJsonPath).toString();
const regexMatches = stringifiedPackageJson.match(new RegExp(dependency, 'g'));
const regexMatches = stringifiedPackageJson.match(new RegExp(`"${dependency}"`, 'g'));
if (regexMatches && regexMatches.length > 1) {
core.setFailed(`Duplicate keys found in package.json: ${regexMatches}`);
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/deduped-package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"dependencies": {
"some-dependency": "1.0.0",
"some-other-dependency": "2.0.0"
"some-dependency-2": "2.0.0"
},
"devDependencies": {
"some-dev-dependency": "2.0.0"
"some-dependency-3": "2.0.0"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/duped-package2.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"some-dependency": "1.0.0",
"some-other-dependency": "2.0.0"
"some-dependency-2": "2.0.0"
},
"devDependencies": {
"some-dependency": "2.0.0"
Expand Down

0 comments on commit 4356c36

Please sign in to comment.