Skip to content

Commit 34378bf

Browse files
committed
add new eslint standard rules
1 parent aafe3bf commit 34378bf

14 files changed

+890
-206
lines changed

.editorconfig

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.{js,jsx,ts,tsx,vue}]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true

package-lock.json

+720-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+24-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"serve": "vue-cli-service serve",
1313
"build": "vue-cli-service build",
1414
"test:unit": "vue-cli-service test:unit",
15-
"test:watch": "vue-cli-service test:unit --watch",
1615
"lint": "vue-cli-service lint",
17-
"build:npm": "vue-cli-service build --target lib --name passwordMeter src/password-meter.vue"
16+
"build:npm": "vue-cli-service build --target lib --name passwordMeter src/password-meter.vue",
17+
"test:watch": "vue-cli-service test:unit --watch"
1818
},
1919
"main": "dist/passwordMeter.umd.js",
2020
"unpkg": "dist/passwordMeter.umd.min.js",
@@ -23,16 +23,21 @@
2323
],
2424
"devDependencies": {
2525
"@vue/cli-plugin-babel": "^4.1.0",
26-
"@vue/cli-plugin-eslint": "^4.1.0",
26+
"@vue/cli-plugin-eslint": "^4.2.2",
2727
"@vue/cli-plugin-unit-jest": "^4.2.2",
2828
"@vue/cli-service": "^4.1.0",
2929
"@vue/eslint-config-prettier": "^6.0.0",
30+
"@vue/eslint-config-standard": "^5.1.0",
3031
"@vue/test-utils": "1.0.0-beta.31",
3132
"babel-eslint": "^10.0.3",
3233
"core-js": "^3.4.4",
33-
"eslint": "^5.16.0",
34+
"eslint": "^6.7.2",
35+
"eslint-plugin-import": "^2.20.1",
36+
"eslint-plugin-node": "^11.0.0",
3437
"eslint-plugin-prettier": "^3.1.2",
35-
"eslint-plugin-vue": "^5.0.0",
38+
"eslint-plugin-promise": "^4.2.1",
39+
"eslint-plugin-standard": "^4.0.0",
40+
"eslint-plugin-vue": "^6.1.2",
3641
"vue": "^2.6.10",
3742
"vue-template-compiler": "^2.6.10"
3843
},
@@ -43,13 +48,25 @@
4348
},
4449
"extends": [
4550
"plugin:vue/essential",
46-
"eslint:recommended"
51+
"eslint:recommended",
52+
"@vue/standard"
4753
],
48-
"rules": {},
54+
"rules": {
55+
"quotes": "error"
56+
},
4957
"parserOptions": {
5058
"parser": "babel-eslint"
5159
},
5260
"overrides": [
61+
{
62+
"files": [
63+
"**/__tests__/*.{j,t}s?(x)",
64+
"**/tests/unit/**/*.spec.{j,t}s?(x)"
65+
],
66+
"env": {
67+
"jest": true
68+
}
69+
},
5370
{
5471
"files": [
5572
"**/__tests__/*.{j,t}s?(x)",

src/App.vue

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@
1818
</template>
1919

2020
<script>
21-
import passwordMeter from "./password-meter.vue";
21+
import passwordMeter from './password-meter.vue'
2222
2323
export default {
24-
name: "app",
24+
name: 'app',
2525
components: {
2626
passwordMeter
2727
},
28-
data() {
28+
data () {
2929
return {
3030
value: null,
3131
score: null
32-
};
32+
}
3333
},
3434
methods: {
35-
onScore({ score, strength }) {
35+
onScore ({ score, strength }) {
3636
// eslint-disable-next-line no-console
37-
console.log(score, strength);
37+
console.log(score, strength)
3838
39-
this.score = score;
39+
this.score = score
4040
}
4141
}
42-
};
42+
}
4343
</script>
4444

4545
<style>

src/logic/checkStrength.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import scorePassword from "./scorePassword";
2-
import nameScore from "./nameScore";
1+
import scorePassword from './scorePassword'
2+
import nameScore from './nameScore'
33

44
const checkStrength = pass => {
5-
const score = scorePassword(pass);
6-
return nameScore(score);
7-
};
5+
const score = scorePassword(pass)
6+
return nameScore(score)
7+
}
88

9-
export default checkStrength;
9+
export default checkStrength

src/logic/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import scorePassword from "./scorePassword";
2-
import nameScore from "./nameScore";
3-
import checkStrength from "./checkStrength";
1+
import scorePassword from './scorePassword'
2+
import nameScore from './nameScore'
3+
import checkStrength from './checkStrength'
44

5-
export { scorePassword, nameScore, checkStrength };
5+
export { scorePassword, nameScore, checkStrength }

src/logic/nameScore.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
const nameScore = score => {
22
switch (score) {
33
case 0:
4-
return "risky";
4+
return 'risky'
55
case 1:
6-
return "guessable";
6+
return 'guessable'
77
case 2:
8-
return "weak";
8+
return 'weak'
99
case 3:
10-
return "safe";
10+
return 'safe'
1111
case 4:
12-
return "secure";
12+
return 'secure'
1313
default:
14-
return null;
14+
return null
1515
}
16-
};
16+
}
1717

18-
export default nameScore;
18+
export default nameScore

src/logic/scorePassword.js

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
const scorePassword = pass => {
2-
let score = 0;
3-
let length = 0;
4-
let specialChar = 0;
5-
let caseMix = 0;
6-
let numCharMix = 0;
7-
8-
let specialCharRegex = /[^A-Za-z0-9]/g;
9-
let lowercaseRegex = /(.*[a-z].*)/g;
10-
let uppercaseRegex = /(.*[A-Z].*)/g;
11-
let numberRegex = /(.*[0-9].*)/g;
12-
let repeatCharRegex = /(\w)(\1+\1+\1+\1+)/g;
13-
14-
let hasSpecialChar = specialCharRegex.test(pass);
15-
let hasLowerCase = lowercaseRegex.test(pass);
16-
let hasUpperCase = uppercaseRegex.test(pass);
17-
let hasNumber = numberRegex.test(pass);
18-
let hasRepeatChars = repeatCharRegex.test(pass);
2+
let score = 0
3+
let length = 0
4+
let specialChar = 0
5+
let caseMix = 0
6+
let numCharMix = 0
7+
8+
const specialCharRegex = /[^A-Za-z0-9]/g
9+
const lowercaseRegex = /(.*[a-z].*)/g
10+
const uppercaseRegex = /(.*[A-Z].*)/g
11+
const numberRegex = /(.*[0-9].*)/g
12+
const repeatCharRegex = /(\w)(\1+\1+\1+\1+)/g
13+
14+
const hasSpecialChar = specialCharRegex.test(pass)
15+
const hasLowerCase = lowercaseRegex.test(pass)
16+
const hasUpperCase = uppercaseRegex.test(pass)
17+
const hasNumber = numberRegex.test(pass)
18+
const hasRepeatChars = repeatCharRegex.test(pass)
1919

2020
if (pass.length > 4) {
2121
if ((hasLowerCase || hasUpperCase) && hasNumber) {
22-
numCharMix = 1;
22+
numCharMix = 1
2323
}
2424

2525
if (hasUpperCase && hasLowerCase) {
26-
caseMix = 1;
26+
caseMix = 1
2727
}
2828

2929
if ((hasLowerCase || hasUpperCase || hasNumber) && hasSpecialChar) {
30-
specialChar = 1;
30+
specialChar = 1
3131
}
3232

3333
if (pass.length > 8) {
34-
length = 1;
34+
length = 1
3535
}
3636

3737
if (pass.length > 12 && !hasRepeatChars) {
38-
length = 2;
38+
length = 2
3939
}
4040

4141
if (pass.length > 25 && !hasRepeatChars) {
42-
length = 3;
42+
length = 3
4343
}
4444

45-
score = length + specialChar + caseMix + numCharMix;
45+
score = length + specialChar + caseMix + numCharMix
4646

4747
if (score > 4) {
48-
score = 4;
48+
score = 4
4949
}
5050
}
5151

52-
return score;
53-
};
52+
return score
53+
}
5454

55-
export default scorePassword;
55+
export default scorePassword

src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import App from './App.vue'
44
Vue.config.productionTip = false
55

66
new Vue({
7-
render: h => h(App),
7+
render: h => h(App)
88
}).$mount('#app')

src/password-meter.vue

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
</template>
44

55
<script>
6-
import { checkStrength, scorePassword } from "./logic";
6+
import { checkStrength, scorePassword } from './logic'
77
88
export default {
9-
name: "password-meter",
9+
name: 'password-meter',
1010
props: {
1111
password: String
1212
},
1313
computed: {
14-
passwordClass() {
14+
passwordClass () {
1515
if (!this.password) {
16-
return null;
16+
return null
1717
}
18-
const strength = checkStrength(this.password);
19-
const score = scorePassword(this.password);
20-
this.$emit("score", { score, strength });
18+
const strength = checkStrength(this.password)
19+
const score = scorePassword(this.password)
20+
this.$emit('score', { score, strength })
2121
return {
2222
[strength]: true,
2323
scored: true
24-
};
24+
}
2525
}
2626
}
27-
};
27+
}
2828
</script>
2929

3030
<style>

tests/password-examples.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export const risky = "sdwasdwq";
2-
export const guessable = "adsasdasd";
3-
export const weak = "asdasd1212";
4-
export const safe = "ASSAasd123";
5-
export const secure = "$p@RYr3y6";
1+
export const risky = 'sdwasdwq'
2+
export const guessable = 'adsasdasd'
3+
export const weak = 'asdasd1212'
4+
export const safe = 'ASSAasd123'
5+
export const secure = '$p@RYr3y6'

tests/unit/logic.spec.js

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
import { checkStrength, scorePassword } from "@/logic";
2-
import { risky, guessable, weak, safe, secure } from "../password-examples";
3-
4-
describe("checkStrength", () => {
5-
it("return risky", () => {
6-
expect(checkStrength(risky)).toBe("risky");
7-
});
8-
9-
it("return guessable", () => {
10-
expect(checkStrength(guessable)).toBe("guessable");
11-
});
12-
13-
it("return weak", () => {
14-
expect(checkStrength(weak)).toBe("weak");
15-
});
16-
17-
it("return safe", () => {
18-
expect(checkStrength(safe)).toBe("safe");
19-
});
20-
21-
it("return secure", () => {
22-
expect(checkStrength(secure)).toBe("secure");
23-
});
24-
});
25-
26-
describe("scorePassword", () => {
27-
it("return risky = 0", () => {
28-
expect(scorePassword(risky)).toBe(0);
29-
});
30-
31-
it("return guessable = 1", () => {
32-
expect(scorePassword(guessable)).toBe(1);
33-
});
34-
35-
it("return weak = 2", () => {
36-
expect(scorePassword(weak)).toBe(2);
37-
});
38-
39-
it("return safe = 3", () => {
40-
expect(scorePassword(safe)).toBe(3);
41-
});
42-
43-
it("return secure = 4", () => {
44-
expect(scorePassword(secure)).toBe(4);
45-
});
46-
});
1+
import { checkStrength, scorePassword } from '@/logic'
2+
import { risky, guessable, weak, safe, secure } from '../password-examples'
3+
4+
describe('checkStrength', () => {
5+
it('return risky', () => {
6+
expect(checkStrength(risky)).toBe('risky')
7+
})
8+
9+
it('return guessable', () => {
10+
expect(checkStrength(guessable)).toBe('guessable')
11+
})
12+
13+
it('return weak', () => {
14+
expect(checkStrength(weak)).toBe('weak')
15+
})
16+
17+
it('return safe', () => {
18+
expect(checkStrength(safe)).toBe('safe')
19+
})
20+
21+
it('return secure', () => {
22+
expect(checkStrength(secure)).toBe('secure')
23+
})
24+
})
25+
26+
describe('scorePassword', () => {
27+
it('return risky = 0', () => {
28+
expect(scorePassword(risky)).toBe(0)
29+
})
30+
31+
it('return guessable = 1', () => {
32+
expect(scorePassword(guessable)).toBe(1)
33+
})
34+
35+
it('return weak = 2', () => {
36+
expect(scorePassword(weak)).toBe(2)
37+
})
38+
39+
it('return safe = 3', () => {
40+
expect(scorePassword(safe)).toBe(3)
41+
})
42+
43+
it('return secure = 4', () => {
44+
expect(scorePassword(secure)).toBe(4)
45+
})
46+
})

0 commit comments

Comments
 (0)