Skip to content

Commit 642b431

Browse files
committed
feat: add lint config
1 parent de8902f commit 642b431

File tree

10 files changed

+201
-135
lines changed

10 files changed

+201
-135
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
coverage
22
dist
33
node_modules
4+
lib

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
'id-length': [
3737
'error',
3838
{
39-
min: 2,
39+
min: 1,
4040
max: 50,
4141
properties: 'never',
4242
exceptions: ['e', 'i', 'n', 't', 'x', 'y', 'z', '_', '$']

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ obj/
6464
# Tests
6565
!tests/**/*.zip
6666

67+
yarn.lock
68+
package-lock.json

.travis.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,4 @@ install:
77
- npm install
88

99
script:
10-
- npm test
11-
12-
notifications:
13-
email:
14-
recipients:
15-
- wjielai@tencent.com
16-
- fysntian@tencent.com
10+
- npm test

commitlint.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const Configuration = {
2+
/*
3+
* Resolve and load @commitlint/config-conventional from node_modules.
4+
* Referenced packages must be installed
5+
*/
6+
extends: ['@commitlint/config-conventional']
7+
}
8+
9+
module.exports = Configuration

lib/cos/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2834,7 +2834,7 @@ function submitRequest(params, callback) {
28342834

28352835
// 处理 headers
28362836
!params.headers && (params.headers = {})
2837-
params.headers['User-Agent'] = "ServerlessFramework"
2837+
params.headers['User-Agent'] = 'ServerlessFramework'
28382838

28392839
// 处理 query
28402840
!params.qs && (params.qs = {})

lib/request/lib/auth.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict'
2-
31
var caseless = require('caseless')
42
var uuid = require('uuid/v4')
53
var helpers = require('./helpers')
64

75
var md5 = helpers.md5
86
var toBase64 = helpers.toBase64
97

10-
function Auth (request) {
8+
function Auth(request) {
119
// define all public properties here
1210
this.request = request
1311
this.hasAuth = false
@@ -17,7 +15,7 @@ function Auth (request) {
1715
this.pass = null
1816
}
1917

20-
Auth.prototype.basic = function (user, pass, sendImmediately) {
18+
Auth.prototype.basic = function(user, pass, sendImmediately) {
2119
var self = this
2220
if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) {
2321
self.request.emit('error', new Error('auth() received invalid user or password'))
@@ -33,7 +31,7 @@ Auth.prototype.basic = function (user, pass, sendImmediately) {
3331
}
3432
}
3533

36-
Auth.prototype.bearer = function (bearer, sendImmediately) {
34+
Auth.prototype.bearer = function(bearer, sendImmediately) {
3735
var self = this
3836
self.bearerToken = bearer
3937
self.hasAuth = true
@@ -47,7 +45,7 @@ Auth.prototype.bearer = function (bearer, sendImmediately) {
4745
}
4846
}
4947

50-
Auth.prototype.digest = function (method, path, authHeader) {
48+
Auth.prototype.digest = function(method, path, authHeader) {
5149
// TODO: More complete implementation of RFC 2617.
5250
// - handle challenge.domain
5351
// - support qop="auth-int" only
@@ -78,19 +76,25 @@ Auth.prototype.digest = function (method, path, authHeader) {
7876
* If the algorithm directive's value is "MD5-sess", then HA1 is
7977
* HA1=MD5(MD5(username:realm:password):nonce:cnonce)
8078
*/
81-
var ha1Compute = function (algorithm, user, realm, pass, nonce, cnonce) {
79+
var ha1Compute = function(algorithm, user, realm, pass, nonce, cnonce) {
8280
var ha1 = md5(user + ':' + realm + ':' + pass)
8381
if (algorithm && algorithm.toLowerCase() === 'md5-sess') {
8482
return md5(ha1 + ':' + nonce + ':' + cnonce)
85-
} else {
86-
return ha1
8783
}
84+
return ha1
8885
}
8986

9087
var qop = /(^|,)\s*auth\s*($|,)/.test(challenge.qop) && 'auth'
9188
var nc = qop && '00000001'
9289
var cnonce = qop && uuid().replace(/-/g, '')
93-
var ha1 = ha1Compute(challenge.algorithm, self.user, challenge.realm, self.pass, challenge.nonce, cnonce)
90+
var ha1 = ha1Compute(
91+
challenge.algorithm,
92+
self.user,
93+
challenge.realm,
94+
self.pass,
95+
challenge.nonce,
96+
cnonce
97+
)
9498
var ha2 = md5(method + ':' + path)
9599
var digestResponse = qop
96100
? md5(ha1 + ':' + challenge.nonce + ':' + nc + ':' + cnonce + ':' + qop + ':' + ha2)
@@ -123,7 +127,7 @@ Auth.prototype.digest = function (method, path, authHeader) {
123127
return authHeader
124128
}
125129

126-
Auth.prototype.onRequest = function (user, pass, sendImmediately, bearer) {
130+
Auth.prototype.onRequest = function(user, pass, sendImmediately, bearer) {
127131
var self = this
128132
var request = self.request
129133

@@ -140,11 +144,13 @@ Auth.prototype.onRequest = function (user, pass, sendImmediately, bearer) {
140144
}
141145
}
142146

143-
Auth.prototype.onResponse = function (response) {
147+
Auth.prototype.onResponse = function(response) {
144148
var self = this
145149
var request = self.request
146150

147-
if (!self.hasAuth || self.sentAuth) { return null }
151+
if (!self.hasAuth || self.sentAuth) {
152+
return null
153+
}
148154

149155
var c = caseless(response.headers)
150156

lib/request/lib/oauth.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
var url = require('url')
42
var qs = require('qs')
53
var caseless = require('caseless')
@@ -8,12 +6,12 @@ var oauth = require('oauth-sign')
86
var crypto = require('crypto')
97
var Buffer = require('safe-buffer').Buffer
108

11-
function OAuth (request) {
9+
function OAuth(request) {
1210
this.request = request
1311
this.params = null
1412
}
1513

16-
OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib) {
14+
OAuth.prototype.buildParams = function(_oauth, uri, method, query, form, qsLib) {
1715
var oa = {}
1816
for (var i in _oauth) {
1917
oa['oauth_' + i] = _oauth[i]
@@ -61,10 +59,16 @@ OAuth.prototype.buildParams = function (_oauth, uri, method, query, form, qsLib)
6159
return oa
6260
}
6361

64-
OAuth.prototype.buildBodyHash = function (_oauth, body) {
62+
OAuth.prototype.buildBodyHash = function(_oauth, body) {
6563
if (['HMAC-SHA1', 'RSA-SHA1'].indexOf(_oauth.signature_method || 'HMAC-SHA1') < 0) {
66-
this.request.emit('error', new Error('oauth: ' + _oauth.signature_method +
67-
' signature_method not supported with body_hash signing.'))
64+
this.request.emit(
65+
'error',
66+
new Error(
67+
'oauth: ' +
68+
_oauth.signature_method +
69+
' signature_method not supported with body_hash signing.'
70+
)
71+
)
6872
}
6973

7074
var shasum = crypto.createHash('sha1')
@@ -74,24 +78,28 @@ OAuth.prototype.buildBodyHash = function (_oauth, body) {
7478
return Buffer.from(sha1, 'hex').toString('base64')
7579
}
7680

77-
OAuth.prototype.concatParams = function (oa, sep, wrap) {
81+
OAuth.prototype.concatParams = function(oa, sep, wrap) {
7882
wrap = wrap || ''
7983

80-
var params = Object.keys(oa).filter(function (i) {
81-
return i !== 'realm' && i !== 'oauth_signature'
82-
}).sort()
84+
var params = Object.keys(oa)
85+
.filter(function(i) {
86+
return i !== 'realm' && i !== 'oauth_signature'
87+
})
88+
.sort()
8389

8490
if (oa.realm) {
8591
params.splice(0, 0, 'realm')
8692
}
8793
params.push('oauth_signature')
8894

89-
return params.map(function (i) {
90-
return i + '=' + wrap + oauth.rfc3986(oa[i]) + wrap
91-
}).join(sep)
95+
return params
96+
.map(function(i) {
97+
return i + '=' + wrap + oauth.rfc3986(oa[i]) + wrap
98+
})
99+
.join(sep)
92100
}
93101

94-
OAuth.prototype.onRequest = function (_oauth) {
102+
OAuth.prototype.onRequest = function(_oauth) {
95103
var self = this
96104
self.params = _oauth
97105

@@ -115,8 +123,12 @@ OAuth.prototype.onRequest = function (_oauth) {
115123
query = uri.query
116124
}
117125
if (transport === 'body' && (method !== 'POST' || contentType !== formContentType)) {
118-
self.request.emit('error', new Error('oauth: transport_method of body requires POST ' +
119-
'and content-type ' + formContentType))
126+
self.request.emit(
127+
'error',
128+
new Error(
129+
'oauth: transport_method of body requires POST ' + 'and content-type ' + formContentType
130+
)
131+
)
120132
}
121133

122134
if (!form && typeof _oauth.body_hash === 'boolean') {
@@ -131,7 +143,7 @@ OAuth.prototype.onRequest = function (_oauth) {
131143
break
132144

133145
case 'query':
134-
var href = self.request.uri.href += (query ? '&' : '?') + self.concatParams(oa, '&')
146+
var href = (self.request.uri.href += (query ? '&' : '?') + self.concatParams(oa, '&'))
135147
self.request.uri = url.parse(href)
136148
self.request.path = self.request.uri.path
137149
break

package.json

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tencent-cloud-sdk",
33
"description": "Tencent Cloud SDK For Serverless Framework",
4-
"version": "0.0.7",
4+
"version": "0.0.8",
55
"main": "./index.js",
66
"publishConfig": {
77
"access": "public"
@@ -12,11 +12,26 @@
1212
"Cloud function"
1313
],
1414
"scripts": {
15-
"test": "echo \"Error: no test specified\" && exit 1",
16-
"lint": "eslint . --fix --cache"
15+
"test": "npm run lint",
16+
"commitlint": "commitlint -f HEAD@{15}",
17+
"lint": "eslint --ext .js,.ts,.tsx .",
18+
"lint:fix": "eslint --fix --ext .js,.ts,.tsx ."
1719
},
18-
"author": "Dfounderliu",
19-
"license": "Apache",
20+
"husky": {
21+
"hooks": {
22+
"pre-commit": "lint-staged",
23+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
24+
"pre-push": "npm run lint"
25+
}
26+
},
27+
"lint-staged": {
28+
"**/*.{js,ts,tsx}": [
29+
"npm run lint",
30+
"git add ."
31+
]
32+
},
33+
"author": "Tencent Cloud, Inc.",
34+
"license": "MIT",
2035
"dependencies": {
2136
"caseless": "0.12.0",
2237
"combined-stream": "1.0.6",
@@ -44,11 +59,15 @@
4459
"xml2js": "0.4.19"
4560
},
4661
"devDependencies": {
62+
"@commitlint/cli": "^8.3.5",
63+
"@commitlint/config-conventional": "^8.3.4",
4764
"babel-eslint": "9.0.0",
4865
"eslint": "5.6.0",
4966
"eslint-config-prettier": "^3.6.0",
5067
"eslint-plugin-import": "^2.18.0",
5168
"eslint-plugin-prettier": "^3.0.1",
69+
"husky": "^4.2.5",
70+
"lint-staged": "^10.2.2",
5271
"prettier": "^1.18.2"
5372
}
5473
}

0 commit comments

Comments
 (0)