File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 11'use strict' ;
22const path = require ( 'path' ) ;
33const isUrl = require ( 'is-url-superb' ) ;
4+ const isGithubUrl = require ( 'is-github-url' ) ;
45const ora = require ( 'ora' ) ;
56const remark = require ( 'remark' ) ;
67const gitClone = require ( 'git-clone' ) ;
@@ -34,9 +35,23 @@ const lint = options => {
3435
3536lint . report = async options => {
3637 const spinner = ora ( 'Linting' ) . start ( ) ;
38+
39+ try {
40+ await lint . _report ( options , spinner ) ;
41+ } catch ( error ) {
42+ spinner . fail ( error . message ) ;
43+ process . exitCode = 1 ;
44+ }
45+ } ;
46+
47+ lint . _report = async ( options , spinner ) => {
3748 let temp = null ;
3849
3950 if ( isUrl ( options . filename ) ) {
51+ if ( ! isGithubUrl ( options . filename , { repository : true } ) ) {
52+ throw new Error ( `Invalid GitHub repo URL: ${ options . filename } ` ) ;
53+ }
54+
4055 temp = tempy . directory ( ) ;
4156 await pify ( gitClone ) ( options . filename , temp ) ;
4257
Original file line number Diff line number Diff line change 4444 "github-url-to-object" : " ^4.0.4" ,
4545 "globby" : " ^9.0.0" ,
4646 "got" : " ^9.6.0" ,
47+ "is-github-url" : " ^1.2.2" ,
4748 "is-url-superb" : " ^2.0.0" ,
4849 "mdast-util-to-string" : " ^1.0.4" ,
4950 "meow" : " ^5.0.0" ,
Original file line number Diff line number Diff line change @@ -7,3 +7,17 @@ test('main', async t => {
77 / M i s s i n g A w e s o m e b a d g e /
88 ) ;
99} ) ;
10+
11+ test ( 'main - non-existent file' , async t => {
12+ await t . throwsAsync (
13+ execa . stderr ( './cli.js' , [ 'test/fixtures/non-existent.md' ] ) ,
14+ / C o u l d n ' t f i n d t h e f i l e /
15+ ) ;
16+ } ) ;
17+
18+ test ( 'main - invalid GitHub repository' , async t => {
19+ await t . throwsAsync (
20+ execa . stderr ( './cli.js' , [ 'https://github.com/sindresorhus/awesome-lint/blob/master/readme.md' ] ) ,
21+ / I n v a l i d G i t H u b r e p o U R L /
22+ ) ;
23+ } ) ;
You can’t perform that action at this time.
0 commit comments