-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add INVALID_REPOSITORY_VALUE rule (#106)
Co-authored-by: bluwy <[email protected]>
- Loading branch information
Showing
14 changed files
with
332 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ | |
"type": "commonjs", | ||
"main": 0, | ||
"module": true, | ||
"jsnext:main": false | ||
"jsnext:main": false, | ||
"repository": 123 | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/tests/fixtures/invalid-repository-value-object-deprecated/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "publint-invalid-repository-value-object-deprecatec", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://www.github.com/bluwy/publint" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/tests/fixtures/invalid-repository-value-object-not-git-url/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "publint-invalid-repository-value-object-not-git-url", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "imap://fake.com/" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
pkg/tests/fixtures/invalid-repository-value-object-shorthand-site/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "publint-invalid-repository-value-object-shorthand-site", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://www.github.com/bluwy/publint" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
pkg/tests/fixtures/invalid-repository-value-shorthand/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "publint-invalid-repository-value-shorthand", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"repository": "npm/npm" | ||
} |
6 changes: 6 additions & 0 deletions
6
pkg/tests/fixtures/invalid-repository-value-string-not-url/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "publint-invalid-repository-value-string-not-url", | ||
"version": "0.0.1", | ||
"type": "commonjs", | ||
"repository": "not_an_url" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,12 @@ import { | |
getCodeFormat, | ||
isCodeCjs, | ||
isCodeEsm, | ||
isDeprecatedGitHubGitUrl, | ||
isFileContentLintable, | ||
isFilePathLintable, | ||
isGitUrl, | ||
isShorthandGitHubOrGitLabUrl, | ||
isShorthandRepositoryUrl, | ||
stripComments | ||
} from '../src/utils.js' | ||
import { createNodeVfs } from '../src/vfs.js' | ||
|
@@ -104,6 +108,64 @@ test('getCodeFormat', () => { | |
} | ||
}) | ||
|
||
test('isGitUrl', () => { | ||
equal(isGitUrl('https://host.xz/path/to/repo.git/'), true) | ||
equal(isGitUrl('http://host.xz/path/to/repo.git/'), true) | ||
equal(isGitUrl('https://host.xz/path/to/repo.git'), true) | ||
equal(isGitUrl('https://subdomain.host.xz/path/to/repo.git'), true) | ||
equal(isGitUrl('https://192.168.0.1/path/to/repo.git'), true) | ||
equal(isGitUrl('https://192.168.0.1:1234/path/to/repo.git'), true) | ||
equal(isGitUrl('http://host.xz/path/to/repo.git'), true) | ||
equal(isGitUrl('git+https://host.xz/path/to/repo.git'), true) | ||
equal(isGitUrl('git+https://host.xz/path/to/repo'), true) | ||
equal(isGitUrl('https://host.xz/path/to/repo.git'), true) | ||
equal(isGitUrl('git+ssh://[email protected]/path/to/repo.git'), true) | ||
equal(isGitUrl('git+ssh://[email protected]/path/to/repo'), true) | ||
equal(isGitUrl('git+ssh://[email protected]:1234/path/to/repo'), true) | ||
equal(isGitUrl('git+ssh://host.xz:1234/path/to/repo'), true) | ||
equal(isGitUrl('git://host.xz/path/to/repo.git'), true) | ||
equal(isGitUrl('git://host.xz/path/to/repo'), true) | ||
equal(isGitUrl('ssh://[email protected]/user/project.git'), true) | ||
equal(isGitUrl('ssh://[email protected]:user/project.git'), true) | ||
equal(isGitUrl('git+ssh://[email protected]/user/project.git'), true) | ||
equal(isGitUrl('git+ssh://[email protected]:user/project.git'), true) | ||
// NOTE: this technically works, but it's quite an edge case and technically not a URL, | ||
// so maybe better to skip this and encourage proper URL format instead | ||
// equal(isGitUrl('[email protected]:react-component/tooltip.git'), true) | ||
|
||
equal(isGitUrl('file://host.xz/path/to/repo'), false) | ||
equal(isGitUrl('/User/foo/bar'), false) | ||
}) | ||
|
||
test('isDeprecatedGitHubGitUrl', () => { | ||
equal(isDeprecatedGitHubGitUrl('git://github.com/user/project.git'), true) | ||
equal(isDeprecatedGitHubGitUrl('https://github.com/user/project'), false) | ||
}) | ||
|
||
test('isShorthandGitHubOrGitLabUrl', () => { | ||
const f = isShorthandGitHubOrGitLabUrl // shorten to please prettier | ||
equal(f('https://github.com/user/project'), true) | ||
equal(f('git+https://github.com/user/project'), true) | ||
equal(f('https://github.com/user/project.git'), true) | ||
equal(f('https://gitlab.com/user/project'), true) | ||
equal(f('git+https://gitlab.com/user/project'), true) | ||
equal(f('https://gitlab.com/user/project.git'), true) | ||
|
||
equal(f('https://bitbucket.com/user/project'), false) | ||
equal(f('https://example.com'), false) | ||
}) | ||
|
||
test('isShortHandRepositoryUrl', () => { | ||
equal(isShorthandRepositoryUrl('user/project'), true) | ||
equal(isShorthandRepositoryUrl('github:user/project'), true) | ||
equal(isShorthandRepositoryUrl('gist:11081aaa281'), true) | ||
equal(isShorthandRepositoryUrl('bitbucket:user/project'), true) | ||
equal(isShorthandRepositoryUrl('gitlab:user/project'), true) | ||
|
||
equal(isShorthandRepositoryUrl('foobar'), false) | ||
equal(isShorthandRepositoryUrl('https://github.com/user/project'), false) | ||
}) | ||
|
||
test('stripComments', () => { | ||
const result = stripComments(` | ||
// hello world | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.