Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f884cd

Browse files
committed
include warnings in packageJson validator
1 parent81603ff commit2f884cd

File tree

4 files changed

+79
-8
lines changed

4 files changed

+79
-8
lines changed

‎lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ var tutorials_1 = require('./tutorials');
1111
exports.tutorials=tutorials_1.default;
1212
varupdate_1=require('./update');
1313
exports.update=update_1.default;
14-
varname_1=require('./validate/name');
15-
exports.validateName=name_1.default;
14+
varpackageJson_1=require('./validate/packageJson');
15+
exports.validatePackageJson=packageJson_1.default;

‎lib/validate/packageJson.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,49 @@ var pJKeys = [{
5656
validate:function(runner){returntypeofrunner==='string'&&runner.length;},
5757
msg:'must specify a test runner',
5858
example:'mocha-coderoad',
59+
},{
60+
name:'repository',
61+
optional:true,
62+
validate:function(repo){
63+
returntypeofrepo==='string'&&repo.length||
64+
typeofrepo==='object'&&repo.hasOwnProperty('type')
65+
&&typeofrepo.type==='string'&&
66+
repo.hasOwnProperty('url')&&typeofrepo.url==='string';
67+
},
68+
msg:'should have a valid repository',
69+
example:'https://github.com/shmck/coderoad-tutorial-name',
70+
},{
71+
name:'bugs',
72+
optional:true,
73+
validate:function(bugs){returntypeofbugs==='object'&&
74+
bugs.hasOwnProperty('url')&&typeofbugs.url==='string';},
75+
msg:'should have a link to where to post bugs',
76+
example:'"bugs": { "url": "https://github.com/shmck/coderoad-tutorial-name" }'
77+
},{
78+
name:'license',
79+
optional:true,
80+
validate:function(license){returntypeoflicense==='string'&&license.length;},
81+
msg:'should have a valid license (ex: MIT, ISC, etc.)',
82+
example:'MIT',
5983
}];
6084
functionvalidatePackageJson(pj){
6185
varerrors=[];
86+
varwarnings=[];
6287
pJKeys.forEach(function(key){
6388
vartarget=pj.config ?pj.config :pj;
6489
if(!target.hasOwnProperty(key.name)||key.validate(target[key.name])){
65-
errors.push({msg:key.msg,example:key.example});
90+
if(!key.optional){
91+
errors.push({msg:key.msg,example:key.example});
92+
}
93+
else{
94+
warnings.push({msg:key.msg,example:key.example});
95+
}
6696
}
6797
});
68-
returnerrors;
98+
return{
99+
errors:errors,
100+
warnings:warnings,
101+
};
69102
}
70103
Object.defineProperty(exports,"__esModule",{value:true});
71104
exports.default=validatePackageJson;

‎src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export {default as search} from './search';
55
export{defaultastutorials}from'./tutorials';
66
export{defaultasupdate}from'./update';
77

8-
export{defaultasvalidateName}from'./validate/name';
8+
export{defaultasvalidatePackageJson}from'./validate/packageJson';

‎src/validate/packageJson.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ const pJKeys: PJKeys[] = [{
5555
validate:runner=>typeofrunner==='string'&&runner.length,
5656
msg:'must specify a test runner',
5757
example:'mocha-coderoad',
58+
},{
59+
name:'repository',
60+
optional:true,
61+
validate:(repo:string|{type:string,url:string})=>{
62+
returntypeofrepo==='string'&&repo.length||
63+
typeofrepo==='object'&&repo.hasOwnProperty('type')
64+
&&typeofrepo.type==='string'&&
65+
repo.hasOwnProperty('url')&&typeofrepo.url==='string';
66+
},
67+
msg:'should have a valid repository',
68+
example:'https://github.com/shmck/coderoad-tutorial-name',
69+
},{
70+
name:'bugs',
71+
optional:true,
72+
validate:(bugs:{url:string})=>typeofbugs==='object'&&
73+
bugs.hasOwnProperty('url')&&typeofbugs.url==='string',
74+
msg:'should have a link to where to post bugs',
75+
example:'"bugs": { "url": "https://github.com/shmck/coderoad-tutorial-name" }'
76+
},{
77+
name:'license',
78+
optional:true,
79+
validate:license=>typeoflicense==='string'&&license.length,
80+
msg:'should have a valid license (ex: MIT, ISC, etc.)',
81+
example:'MIT',
5882
}];
5983

6084
interfacePJErrors{
@@ -66,17 +90,31 @@ interface PJKeys extends PJErrors {
6690
name:string;
6791
validate:(content:string)=>boolean;
6892
config?:boolean;
93+
optional?:boolean;
94+
}
95+
96+
interfaceValidatePjOutput{
97+
errors:PJErrors[];
98+
warnings:PJErrors[];
6999
}
70100

71-
exportdefaultfunctionvalidatePackageJson(pj:PackageJson):PJErrors[]{
101+
exportdefaultfunctionvalidatePackageJson(pj:PackageJson):ValidatePjOutput{
72102
consterrors=[];
103+
constwarnings=[];
73104
pJKeys.forEach(key=>{
74105
// key on pj or pj.config
75106
consttarget=pj.config ?pj.config :pj;
76107
// key doesn't exist or key is invalid
77108
if(!target.hasOwnProperty(key.name)||key.validate(target[key.name])){
78-
errors.push({msg:key.msg,example:key.example});
109+
if(!key.optional){
110+
errors.push({msg:key.msg,example:key.example});
111+
}else{
112+
warnings.push({msg:key.msg,example:key.example});
113+
}
79114
}
80115
});
81-
returnerrors;
116+
return{
117+
errors,
118+
warnings,
119+
};
82120
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp