Skip to content

Commit 0e71720

Browse files
committed
ref #25 Support enableOnStart flag on text normalisation rules
1 parent 5becc63 commit 0e71720

File tree

4 files changed

+70
-50
lines changed

4 files changed

+70
-50
lines changed

lib/normalisation-rule-store.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const isEqual = require('lodash.isequal')
2+
const omit = require('lodash.omit')
23
const clone = value => JSON.parse(JSON.stringify(value))
34

45
class NormalisationRuleStore {
@@ -9,11 +10,15 @@ class NormalisationRuleStore {
910

1011
_setupRules (rules) {
1112
this._baseRules = clone(rules)
12-
this._rules = this._markAllActive(this._baseRules)
13+
this._rules = this._resetRuleStatus(this._baseRules)
1314
}
1415

15-
_markAllActive (rules) {
16-
return rules.map(rule => Object.assign({}, rule, { active: true }))
16+
_resetRuleStatus (rules) {
17+
return rules.map(rule =>
18+
Object.assign({}, omit(rule, ['enableOnStart']), {
19+
active: rule.enableOnStart !== false
20+
})
21+
)
1722
}
1823

1924
getAllRules () {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
},
140140
"scripts": {
141141
"coverage": "nyc yarn test",
142+
"format": "prettier-eslint --write '*.js' 'lib/**/*.js' 'test/**/*.js'",
142143
"lint": "eslint .",
143144
"postinstall": "node ./node_modules/vscode/bin/install",
144145
"prep": "yarn run lint && yarn test",
@@ -149,7 +150,8 @@
149150
},
150151
"dependencies": {
151152
"clipboardy": "1.1.2",
152-
"lodash.isequal": "4.5.0"
153+
"lodash.isequal": "4.5.0",
154+
"lodash.omit": "4.5.0"
153155
},
154156
"devDependencies": {
155157
"chai": "^4.1.2",

test/lib/normalisation-rule-store.test.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,42 @@ suite('NormalisationRuleStore', () => {
77
beforeEach(() => {
88
configStore = {
99
preComparisonTextNormalizationRules: [
10-
{ name: 'RULE1' },
11-
{ name: 'RULE2' }
10+
{ name: 'RULE1', enableOnStart: true },
11+
{ name: 'RULE2', enableOnStart: true },
12+
{ name: 'RULE3', enableOnStart: false },
13+
{ name: 'RULE4' }
1214
]
1315
}
1416
ruleStore = new NormalisationRuleStore({ configStore })
1517
})
1618

17-
test('it gives pre-comparison text normalization rules from config as active rules', () => {
19+
test('it gives pre-comparison text normalization rules from config', () => {
1820
expect(ruleStore.getAllRules()).to.eql([
1921
{ name: 'RULE1', active: true },
20-
{ name: 'RULE2', active: true }
22+
{ name: 'RULE2', active: true },
23+
{ name: 'RULE3', active: false },
24+
{ name: 'RULE4', active: true }
2125
])
2226
})
2327

24-
test('it marks specified rules as disabled', () => {
28+
test('it marks unspecified rules as disabled', () => {
2529
const activeRuleIndices = [1]
2630
ruleStore.specifyActiveRules(activeRuleIndices)
27-
expect(ruleStore.getAllRules()).to.eql([
28-
{ name: 'RULE1', active: false },
29-
{ name: 'RULE2', active: true }
30-
])
31+
const [firstRule] = ruleStore.getAllRules()
32+
expect(firstRule).to.eql({ name: 'RULE1', active: false })
3133
})
3234

33-
test('it sets all rules activates if rule set is updated in the editor config', () => {
35+
test('it resets all rule states in the editor config', () => {
3436
const activeRuleIndices = [1]
3537
ruleStore.specifyActiveRules(activeRuleIndices)
36-
configStore.preComparisonTextNormalizationRules.pop()
37-
expect(ruleStore.getAllRules()).to.eql([{ name: 'RULE1', active: true }])
38+
configStore.preComparisonTextNormalizationRules.push({ name: 'RULE_TMP' })
39+
expect(ruleStore.getAllRules()).to.eql([
40+
{ name: 'RULE1', active: true },
41+
{ name: 'RULE2', active: true },
42+
{ name: 'RULE3', active: false },
43+
{ name: 'RULE4', active: true },
44+
{ name: 'RULE_TMP', active: true }
45+
])
3846
})
3947

4048
test('it returns all the active rules', () => {

yarn.lock

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ buffer-from@^1.0.0:
385385
version "1.0.0"
386386
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.0.0.tgz#4cb8832d23612589b0406e9e2956c17f06fdf531"
387387

388-
builtin-modules@^1.0.0, builtin-modules@^1.1.1:
388+
builtin-modules@^1.0.0:
389389
version "1.1.1"
390390
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
391391

@@ -482,8 +482,8 @@ chalk@^1.0.0, chalk@^1.1.1, chalk@^1.1.3:
482482
supports-color "^2.0.0"
483483

484484
chalk@^2.0.0, chalk@^2.1.0:
485-
version "2.3.2"
486-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.2.tgz#250dc96b07491bfd601e648d66ddf5f60c7a5c65"
485+
version "2.4.0"
486+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.0.tgz#a060a297a6b57e15b61ca63ce84995daa0fe6e52"
487487
dependencies:
488488
ansi-styles "^3.2.1"
489489
escape-string-regexp "^1.0.5"
@@ -946,10 +946,9 @@ eslint-module-utils@^2.2.0:
946946
pkg-dir "^1.0.0"
947947

948948
eslint-plugin-import@^2.10.0:
949-
version "2.10.0"
950-
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.10.0.tgz#fa09083d5a75288df9c6c7d09fe12255985655e7"
949+
version "2.11.0"
950+
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.11.0.tgz#15aeea37a67499d848e8e981806d4627b5503816"
951951
dependencies:
952-
builtin-modules "^1.1.1"
953952
contains-path "^0.1.0"
954953
debug "^2.6.8"
955954
doctrine "1.5.0"
@@ -959,6 +958,7 @@ eslint-plugin-import@^2.10.0:
959958
lodash "^4.17.4"
960959
minimatch "^3.0.3"
961960
read-pkg-up "^2.0.0"
961+
resolve "^1.6.0"
962962

963963
eslint-plugin-node@^6.0.1:
964964
version "6.0.1"
@@ -2078,9 +2078,9 @@ istanbul-lib-source-maps@^1.2.3:
20782078
rimraf "^2.6.1"
20792079
source-map "^0.5.3"
20802080

2081-
istanbul-reports@^1.1.4:
2082-
version "1.3.0"
2083-
resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.3.0.tgz#2f322e81e1d9520767597dca3c20a0cce89a3554"
2081+
istanbul-reports@^1.4.0:
2082+
version "1.4.0"
2083+
resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.4.0.tgz#3d7b44b912ecbe7652a603662b962120739646a1"
20842084
dependencies:
20852085
handlebars "^4.0.3"
20862086

@@ -2297,6 +2297,10 @@ lodash.merge@^4.6.0:
22972297
version "4.6.1"
22982298
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"
22992299

2300+
lodash.omit@4.5.0:
2301+
version "4.5.0"
2302+
resolved "https://registry.yarnpkg.com/lodash.omit/-/lodash.omit-4.5.0.tgz#6eb19ae5a1ee1dd9df0b969e66ce0b7fa30b5e60"
2303+
23002304
lodash.restparam@^3.0.0:
23012305
version "3.6.1"
23022306
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
@@ -2478,7 +2482,7 @@ mimic-fn@^1.0.0:
24782482
version "1.2.0"
24792483
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022"
24802484

2481-
"minimatch@2 || 3", minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
2485+
"minimatch@2 || 3", minimatch@3.0.4, minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
24822486
version "3.0.4"
24832487
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
24842488
dependencies:
@@ -2525,8 +2529,8 @@ mocha@^4.0.1:
25252529
supports-color "4.4.0"
25262530

25272531
mocha@^5.0.5:
2528-
version "5.0.5"
2529-
resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.0.5.tgz#e228e3386b9387a4710007a641f127b00be44b52"
2532+
version "5.1.1"
2533+
resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.1.1.tgz#b774c75609dac05eb48f4d9ba1d827b97fde8a7b"
25302534
dependencies:
25312535
browser-stdout "1.3.1"
25322536
commander "2.11.0"
@@ -2536,6 +2540,7 @@ mocha@^5.0.5:
25362540
glob "7.1.2"
25372541
growl "1.10.3"
25382542
he "1.1.1"
2543+
minimatch "3.0.4"
25392544
mkdirp "0.5.1"
25402545
supports-color "4.4.0"
25412546

@@ -2588,8 +2593,8 @@ next-tick@1:
25882593
resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.0.0.tgz#ca86d1fe8828169b0120208e3dc8424b9db8342c"
25892594

25902595
nise@^1.2.0:
2591-
version "1.3.2"
2592-
resolved "https://registry.yarnpkg.com/nise/-/nise-1.3.2.tgz#fd6fd8dc040dfb3c0a45252feb6ff21832309b14"
2596+
version "1.3.3"
2597+
resolved "https://registry.yarnpkg.com/nise/-/nise-1.3.3.tgz#c17a850066a8a1dfeb37f921da02441afc4a82ba"
25932598
dependencies:
25942599
"@sinonjs/formatio" "^2.0.0"
25952600
just-extend "^1.1.27"
@@ -2635,8 +2640,8 @@ number-is-nan@^1.0.0:
26352640
resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d"
26362641

26372642
nyc@^11.6.0:
2638-
version "11.6.0"
2639-
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.6.0.tgz#d9c7b51ffceb6bba099a4683a6adc1b331b98853"
2643+
version "11.7.1"
2644+
resolved "https://registry.yarnpkg.com/nyc/-/nyc-11.7.1.tgz#7cb0a422e501b88ff2c1634341dec2560299d67b"
26402645
dependencies:
26412646
archy "^1.0.0"
26422647
arrify "^1.0.1"
@@ -2653,7 +2658,7 @@ nyc@^11.6.0:
26532658
istanbul-lib-instrument "^1.10.0"
26542659
istanbul-lib-report "^1.1.3"
26552660
istanbul-lib-source-maps "^1.2.3"
2656-
istanbul-reports "^1.1.4"
2661+
istanbul-reports "^1.4.0"
26572662
md5-hex "^1.2.0"
26582663
merge-source-map "^1.0.2"
26592664
micromatch "^2.3.11"
@@ -2952,8 +2957,8 @@ prettier-eslint@^8.5.0:
29522957
typescript-eslint-parser "^11.0.0"
29532958

29542959
prettier@^1.12.0, prettier@^1.7.0:
2955-
version "1.12.0"
2956-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.12.0.tgz#d26fc5894b9230de97629b39cae225b503724ce8"
2960+
version "1.12.1"
2961+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.12.1.tgz#c1ad20e803e7749faf905a409d2367e06bbe7325"
29572962

29582963
pretty-format@^22.0.3:
29592964
version "22.4.3"
@@ -2986,9 +2991,9 @@ qs@~6.5.1:
29862991
version "6.5.1"
29872992
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8"
29882993

2989-
querystringify@~1.0.0:
2990-
version "1.0.0"
2991-
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-1.0.0.tgz#6286242112c5b712fa654e526652bf6a13ff05cb"
2994+
querystringify@^2.0.0:
2995+
version "2.0.0"
2996+
resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.0.0.tgz#fa3ed6e68eb15159457c89b37bc6472833195755"
29922997

29932998
queue@^3.1.0:
29942999
version "3.1.0"
@@ -3198,7 +3203,7 @@ require-uncached@^1.0.3:
31983203
caller-path "^0.1.0"
31993204
resolve-from "^1.0.0"
32003205

3201-
requires-port@~1.0.0:
3206+
requires-port@^1.0.0:
32023207
version "1.0.0"
32033208
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
32043209

@@ -3218,7 +3223,7 @@ resolve-url@^0.2.1:
32183223
version "0.2.1"
32193224
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
32203225

3221-
resolve@^1.3.3, resolve@^1.5.0:
3226+
resolve@^1.3.3, resolve@^1.5.0, resolve@^1.6.0:
32223227
version "1.7.1"
32233228
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.7.1.tgz#aadd656374fd298aee895bc026b8297418677fd3"
32243229
dependencies:
@@ -3264,8 +3269,8 @@ rx-lite@*, rx-lite@^4.0.8:
32643269
resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-4.0.8.tgz#0b1e11af8bc44836f04a6407e92da42467b79444"
32653270

32663271
rxjs@^5.3.0:
3267-
version "5.5.9"
3268-
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.9.tgz#12a0487794b00f5eb370fec2751bd973a89886fb"
3272+
version "5.5.10"
3273+
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.10.tgz#fde02d7a614f6c8683d0d1957827f492e09db045"
32693274
dependencies:
32703275
symbol-observable "1.0.1"
32713276

@@ -3624,8 +3629,8 @@ supports-color@^4.0.0:
36243629
has-flag "^2.0.0"
36253630

36263631
supports-color@^5.1.0, supports-color@^5.3.0:
3627-
version "5.3.0"
3628-
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.3.0.tgz#5b24ac15db80fa927cf5227a4a33fd3c4c7676c0"
3632+
version "5.4.0"
3633+
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
36293634
dependencies:
36303635
has-flag "^3.0.0"
36313636

@@ -3792,8 +3797,8 @@ typescript-eslint-parser@^11.0.0:
37923797
semver "5.4.1"
37933798

37943799
typescript@^2.5.1:
3795-
version "2.8.1"
3796-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.1.tgz#6160e4f8f195d5ba81d4876f9c0cc1fbc0820624"
3800+
version "2.8.3"
3801+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.8.3.tgz#5d817f9b6f31bb871835f4edf0089f21abe6c170"
37973802

37983803
uglify-js@^2.6:
37993804
version "2.8.29"
@@ -3836,11 +3841,11 @@ urix@^0.1.0:
38363841
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
38373842

38383843
url-parse@^1.1.9:
3839-
version "1.3.0"
3840-
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.3.0.tgz#04a06c420d22beb9804f7ada2d57ad13160a4258"
3844+
version "1.4.0"
3845+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.4.0.tgz#6bfdaad60098c7fe06f623e42b22de62de0d3d75"
38413846
dependencies:
3842-
querystringify "~1.0.0"
3843-
requires-port "~1.0.0"
3847+
querystringify "^2.0.0"
3848+
requires-port "^1.0.0"
38443849

38453850
use@^3.1.0:
38463851
version "3.1.0"

0 commit comments

Comments
 (0)