Skip to content

Commit

Permalink
fix: Fix no-git-dependencies rule (#508)
Browse files Browse the repository at this point in the history
The `no-git-dependencies` rule incorrectly identifies an archive URL as a git URL.

Added the `.tgz` common archive format to the `isArchiveUrl` function.
This fixes both the `no-git-dependencies` and `no-git-devDependencies`
rules.
  • Loading branch information
shaneog authored Oct 28, 2021
1 parent ae0c6f2 commit 22ed964
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validators/dependency-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const isGithubRepositoryShortcut = (version) => {
* @return {boolean} True if the version is url to archive
*/
const isArchiveUrl = (version) => {
return version.endsWith('.tar.gz') || version.endsWith('.zip');
return version.endsWith('.tgz') || version.endsWith('.tar.gz') || version.endsWith('.zip');
};

/**
Expand Down
14 changes: 14 additions & 0 deletions test/unit/rules/no-git-dependencies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,18 @@ describe('no-git-dependencies Unit Tests', () => {
expect(response).toBe(true);
});
});

describe('when package.json has node with an archive URL', () => {
test('true should be returned', () => {
const packageJsonData = {
dependencies: {
'my-module-v3':
'https://registry.npmjs.org/npm-package-json-lint-config-default/-/npm-package-json-lint-config-default-3.0.0.tgz',
},
};
const response = lint(packageJsonData, 'error');

expect(response).toBe(true);
});
});
});
14 changes: 14 additions & 0 deletions test/unit/rules/no-git-devDependencies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,18 @@ describe('no-git-devDependencies Unit Tests', () => {
expect(response).toBe(true);
});
});

describe('when package.json has node with an archive URL', () => {
test('true should be returned', () => {
const packageJsonData = {
devDependencies: {
'my-module-v3':
'https://registry.npmjs.org/npm-package-json-lint-config-default/-/npm-package-json-lint-config-default-3.0.0.tgz',
},
};
const response = lint(packageJsonData, 'error');

expect(response).toBe(true);
});
});
});

0 comments on commit 22ed964

Please sign in to comment.