From 239699446deb98cbe432cc18e3db11d5fa0660ba Mon Sep 17 00:00:00 2001 From: pawel idzikowski Date: Sun, 4 Sep 2022 19:02:09 +0200 Subject: [PATCH 1/4] Update PositionedKeywords.test.js --- test/rules/v1/js/PositionedKeywords.test.js | 127 ++++++++++++++++++-- 1 file changed, 117 insertions(+), 10 deletions(-) diff --git a/test/rules/v1/js/PositionedKeywords.test.js b/test/rules/v1/js/PositionedKeywords.test.js index 79444229..7b23fe4b 100644 --- a/test/rules/v1/js/PositionedKeywords.test.js +++ b/test/rules/v1/js/PositionedKeywords.test.js @@ -13,13 +13,13 @@ const PositionedKeywordsRule = require('src/rules/v1/common/PositionedKeywords') const requireKeywordBOFConfig = { name: 'require', - regex: /const.*(?:require|{)/, + regex: 'const.*(?:require|{)', position: { BOF: true, custom: null }, - enforced: true, maxLineBreaks: 0, + enforced: true, breakOnFirstOccurence: false, countDifferentCodeAsLineBreak: false, multiLineOptions: [ @@ -28,19 +28,18 @@ const requireKeywordBOFConfig = { notIncludes: 'require' }, limiter: { - startsWith: '} = require', - indentation: 'eq-indicator' + startsWith: '} = require' } } ], order: [ { name: 'packages', - regex: /require(?!.*@).*/ + regex: 'require(?!.*[@,.]/)' }, { - name: 'other', - regex: /require.*/ + name: 'others', + regex: 'require(.*[@,.]/)' } ] }; @@ -106,7 +105,7 @@ describe('invoke function', () => { `@@ -10,13 +1,7 @@`, `-removed line`, `+some code`, - `+const method1 = require('@/helpers/methods');`, + `+const method1 = require('../helpers/methods');`, `-`, `+const {`, `+ method2`, @@ -140,7 +139,7 @@ describe('invoke function', () => { `+const {`, `+ method2`, `+ method3`, - `+} = require('@/helpers/methods2')`, + `+} = require('./helpers/methods2')`, `+const method1 = require('@/helpers/methods');` ] } @@ -164,7 +163,7 @@ describe('invoke function', () => { `+const {`, `+ method2`, `+ method3`, - `+} = require('@/helpers/methods2')`, + `+} = require('./helpers/methods2')`, `+`, `+const method4 = require('package2');` ] @@ -180,4 +179,112 @@ describe('invoke function', () => { expect(result[1]).toHaveProperty('line', 11); }); + + it('returns empty array on valid require order (example1, enforced)', () => { + const positionedKeywordsRule = new PositionedKeywordsRule( + patchronContext, + validConfig, + { + ...file, + splitPatch: [ + `@@ -10,13 +5,7 @@`, + `+const method4 = require('package2');`, + `+const {`, + `+ method2`, + `+ method3`, + `+} = require('./helpers/methods2')`, + `+const method1 = require('@/helpers/methods');` + ] + } + ); + + const result = positionedKeywordsRule.invoke(); + + expect(result).toEqual([]); + }); + + it('returns review on invalid require order (example1, enforced)', () => { + const positionedKeywordsRule = new PositionedKeywordsRule( + patchronContext, + validConfig, + { + ...file, + splitPatch: [ + `@@ -10,13 +5,7 @@`, + `+const {`, + `+ method2`, + `+ method3`, + `+} = require('./helpers/methods2')`, + `+const method1 = require('@/helpers/methods');`, + `+const method4 = require('package2');` + ] + } + ); + + const result = positionedKeywordsRule.invoke(); + + expect(result).toHaveLength(1); + + expect(result[0]).toHaveProperty('line', 10); + }); + + it('returns empty array on valid require order (example2, enforced)', () => { + const positionedKeywordsRule = new PositionedKeywordsRule( + patchronContext, + validConfig, + { + ...file, + splitPatch: [ + `@@ -10,13 +5,7 @@`, + `+const {`, + `+ method5`, + `+ method6`, + `+} = require('package3')`, + `+const method4 = require('package2');`, + `+const method7 = require('package3/index');`, + `+const {`, + `+ method2`, + `+ method3`, + `+} = require('./helpers/methods2')`, + `+const method1 = require('@/helpers/methods');` + ] + } + ); + + const result = positionedKeywordsRule.invoke(); + + expect(result).toEqual([]); + }); + + it('returns review on invalid require order (example2, enforced)', () => { + const positionedKeywordsRule = new PositionedKeywordsRule( + patchronContext, + validConfig, + { + ...file, + splitPatch: [ + `@@ -10,13 +5,7 @@`, + `+const method7 = require('package3/index');`, + `+const {`, + `+ method2`, + `+ method3`, + `+} = require('./helpers/methods2')`, + `+const method1 = require('@/helpers/methods');`, + `+const {`, + `+ method5`, + `+ method6`, + `+} = require('package3')`, + `+const method4 = require('package2');` + ] + } + ); + + const result = positionedKeywordsRule.invoke(); + + expect(result).toHaveLength(2); + + expect(result[0]).toHaveProperty('line', 11); + + expect(result[1]).toHaveProperty('line', 15); + }); }); From 0971a221250f7b2f69bed391c34388f039b8217d Mon Sep 17 00:00:00 2001 From: pawel idzikowski Date: Sun, 4 Sep 2022 19:05:41 +0200 Subject: [PATCH 2/4] Update PositionedKeywords.test.js --- test/rules/v1/js/PositionedKeywords.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/rules/v1/js/PositionedKeywords.test.js b/test/rules/v1/js/PositionedKeywords.test.js index 7b23fe4b..7d2249ff 100644 --- a/test/rules/v1/js/PositionedKeywords.test.js +++ b/test/rules/v1/js/PositionedKeywords.test.js @@ -70,7 +70,7 @@ describe('invoke function', () => { * --------------------------------------------------- */ - it('returns empty array on valid require BOF position', () => { + it('returns empty array on valid require BOF position + order', () => { const positionedKeywordsRule = new PositionedKeywordsRule( patchronContext, validConfig, @@ -95,7 +95,7 @@ describe('invoke function', () => { expect(result).toEqual([]); }); - it('returns review on invalid require BOF position', () => { + it('returns review on invalid require BOF position + order', () => { const positionedKeywordsRule = new PositionedKeywordsRule( patchronContext, validConfig, @@ -126,7 +126,7 @@ describe('invoke function', () => { expect(result[1]).toHaveProperty('line', 8); }); - it('returns empty array on valid require BOF position (enforced)', () => { + it('returns empty array on valid require BOF position + order (enforced)', () => { const positionedKeywordsRule = new PositionedKeywordsRule( patchronContext, validConfig, @@ -150,7 +150,7 @@ describe('invoke function', () => { expect(result).toEqual([]); }); - it('returns review on invalid require BOF position (enforced)', () => { + it('returns review on invalid require BOF position + order (enforced)', () => { const positionedKeywordsRule = new PositionedKeywordsRule( patchronContext, validConfig, From 9c3cba3269647b9e8e34e4c4c4dbcaf5da5eddf5 Mon Sep 17 00:00:00 2001 From: pawel idzikowski Date: Mon, 5 Sep 2022 16:39:28 +0200 Subject: [PATCH 3/4] Update PositionedKeywords.test.js Update PositionedKeywords.test.js --- test/rules/v1/vue/PositionedKeywords.test.js | 55 ++++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/test/rules/v1/vue/PositionedKeywords.test.js b/test/rules/v1/vue/PositionedKeywords.test.js index 840d4ae2..49efeb01 100644 --- a/test/rules/v1/vue/PositionedKeywords.test.js +++ b/test/rules/v1/vue/PositionedKeywords.test.js @@ -11,16 +11,9 @@ const setupPatchronContext = require('test/setupPatchronContext'); const initializeFile = require('test/rules/helpers/initializeFile'); const PositionedKeywordsRule = require('src/rules/v1/common/PositionedKeywords'); -const importKeywordCustomConfig = { +const importKeywordBaseConfig = { name: 'import', - regex: /import.*/, - position: { - custom: { - name: '