Skip to content

Commit

Permalink
controlled-versions: ignore git and file links (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-at authored Jun 13, 2021
1 parent 3fb2793 commit 3334990
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions __tests__/rules/controlled-versions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ tester.run("controlled-versions", rule, {
filename: "package.json",
options: [{ granularity: "minor", excludePatterns: ["foo*"] }],
},
// ignores git links
{
code: `{
"name": "p1",
"dependencies": {
"foo1": "git://github.com/foo/foo1.git",
"foo2": "git+ssh://[email protected]:foo/foo2.git",
"foo3": "git+http://[email protected]/foo/foo3",
"foo4": "git+https://[email protected]/foo/foo4",
"foo5": "git+file:///path/to/file"
}
}`,
filename: "package.json",
options: [{ granularity: "minor" }],
},
// ignores file links
{
code: `{
"name": "p1",
"dependencies": {
"foo1": "file:../relative/path/to/file",
"foo1": "file:/full/path/to/file"
}
}`,
filename: "package.json",
options: [{ granularity: "minor" }],
},
],
invalid: [
// fixed without explicitly passing granularity
Expand Down
6 changes: 5 additions & 1 deletion src/rules/controlled-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { Dependencies, DependencyGranularity } from "../types";
import micromatch from "micromatch";
import { toControlledSemver } from "../to-controlled-semver";

const isGitDependency = (version: string): boolean => version.startsWith("git");
const isFileDependency = (version: string): boolean => version.startsWith("file");

const isFixedVersion = (version: string): boolean => {
const cleanedSemver = cleanSemver(version);

Expand Down Expand Up @@ -101,7 +104,8 @@ const rule: Rule.RuleModule = {
.pickBy(
(_, dependency) =>
micromatch([dependency], excludePatterns).length === 0
)
)
.omitBy((version) => isGitDependency(version!) || isFileDependency(version!))
.forEach((version, dependency) => {
if (!version) {
return;
Expand Down

0 comments on commit 3334990

Please sign in to comment.