@luxfi/biome-config 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base.jsonc +3 -3
- package/compiled/base.json +90 -90
- package/package.json +3 -16
- package/scripts/generate.js +1 -81
- package/project.json +0 -27
- package/src/extractor.js +0 -44
- package/src/extractor.test.js +0 -138
- package/src/fixtures/array-merge-config.jsonc +0 -52
- package/src/fixtures/no-markers-config.jsonc +0 -37
- package/src/fixtures/off-override-config.jsonc +0 -41
- package/src/fixtures/simple-config.jsonc +0 -45
- package/src/merger.js +0 -100
- package/src/merger.test.js +0 -178
- package/src/processor.js +0 -121
- package/src/processor.test.js +0 -336
- package/src/universePackages.js +0 -144
package/project.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tags": ["scope:biome-config", "type:tooling"],
|
|
3
|
-
"targets": {
|
|
4
|
-
"prepare": {
|
|
5
|
-
"command": "bun ./scripts/generate.js && biome check --write",
|
|
6
|
-
"options": {
|
|
7
|
-
"cwd": "{projectRoot}"
|
|
8
|
-
},
|
|
9
|
-
"cache": true,
|
|
10
|
-
"inputs": [
|
|
11
|
-
"{projectRoot}/base.jsonc",
|
|
12
|
-
"{projectRoot}/scripts/**",
|
|
13
|
-
"{projectRoot}/src/**",
|
|
14
|
-
"{projectRoot}/package.json"
|
|
15
|
-
],
|
|
16
|
-
"outputs": ["{projectRoot}/compiled/base.json"]
|
|
17
|
-
},
|
|
18
|
-
"test": {
|
|
19
|
-
"command": "bun test",
|
|
20
|
-
"options": {
|
|
21
|
-
"cwd": "{projectRoot}"
|
|
22
|
-
},
|
|
23
|
-
"cache": true,
|
|
24
|
-
"inputs": ["{projectRoot}/src/**", "{projectRoot}/scripts/**"]
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/extractor.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extracts all rule values from main linter config into a path-keyed lookup map
|
|
3
|
-
* @param {Object} mainConfig - The main linter configuration object
|
|
4
|
-
* @returns {Map<string, any>} Map of rule paths (e.g., "linter.rules.style.noRestrictedImports") to their values
|
|
5
|
-
*/
|
|
6
|
-
function extractGlobalRuleValues(mainConfig) {
|
|
7
|
-
const ruleMap = new Map()
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Recursively walks rules tree to extract all rule configurations
|
|
11
|
-
* @param {Object} obj - Current object being walked
|
|
12
|
-
* @param {Array<string>} pathParts - Path components leading to this object
|
|
13
|
-
*/
|
|
14
|
-
function walkRules(obj, pathParts) {
|
|
15
|
-
if (!obj || typeof obj !== 'object') {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
20
|
-
const currentPath = [...pathParts, key]
|
|
21
|
-
const pathString = currentPath.join('.')
|
|
22
|
-
|
|
23
|
-
// Store this rule value if it looks like a rule configuration
|
|
24
|
-
// Rules have a "level" property, or are "off"/"error"/"warn" strings
|
|
25
|
-
if (value && typeof value === 'object' && (value.level || value.options)) {
|
|
26
|
-
ruleMap.set(pathString, value)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Continue walking nested objects (but not arrays)
|
|
30
|
-
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
31
|
-
walkRules(value, currentPath)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Start walking from linter.rules
|
|
37
|
-
if (mainConfig.linter?.rules) {
|
|
38
|
-
walkRules(mainConfig.linter.rules, ['linter', 'rules'])
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return ruleMap
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
module.exports = { extractGlobalRuleValues }
|
package/src/extractor.test.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { extractGlobalRuleValues } from './extractor.js'
|
|
3
|
-
|
|
4
|
-
describe('extractGlobalRuleValues', () => {
|
|
5
|
-
test('should extract simple rule values', () => {
|
|
6
|
-
const config = {
|
|
7
|
-
linter: {
|
|
8
|
-
rules: {
|
|
9
|
-
style: {
|
|
10
|
-
noRestrictedImports: {
|
|
11
|
-
level: 'error',
|
|
12
|
-
options: {
|
|
13
|
-
paths: {
|
|
14
|
-
lodash: 'Use lodash-es',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const result = extractGlobalRuleValues(config)
|
|
24
|
-
|
|
25
|
-
expect(result.has('linter.rules.style.noRestrictedImports')).toBe(true)
|
|
26
|
-
expect(result.get('linter.rules.style.noRestrictedImports')).toMatchObject({
|
|
27
|
-
level: 'error',
|
|
28
|
-
options: {
|
|
29
|
-
paths: {
|
|
30
|
-
lodash: 'Use lodash-es',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
test('should extract nested rule values', () => {
|
|
37
|
-
const config = {
|
|
38
|
-
linter: {
|
|
39
|
-
rules: {
|
|
40
|
-
complexity: {
|
|
41
|
-
noExtraBooleanCast: {
|
|
42
|
-
level: 'error',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
style: {
|
|
46
|
-
noNegationElse: {
|
|
47
|
-
level: 'warn',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const result = extractGlobalRuleValues(config)
|
|
55
|
-
|
|
56
|
-
expect(result.size).toBe(2)
|
|
57
|
-
expect(result.has('linter.rules.complexity.noExtraBooleanCast')).toBe(true)
|
|
58
|
-
expect(result.has('linter.rules.style.noNegationElse')).toBe(true)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test('should handle config without linter rules', () => {
|
|
62
|
-
const config = {
|
|
63
|
-
formatter: {
|
|
64
|
-
enabled: true,
|
|
65
|
-
},
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const result = extractGlobalRuleValues(config)
|
|
69
|
-
|
|
70
|
-
expect(result.size).toBe(0)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('should handle empty linter rules', () => {
|
|
74
|
-
const config = {
|
|
75
|
-
linter: {
|
|
76
|
-
rules: {},
|
|
77
|
-
},
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const result = extractGlobalRuleValues(config)
|
|
81
|
-
|
|
82
|
-
expect(result.size).toBe(0)
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
test('should only extract objects with level or options', () => {
|
|
86
|
-
const config = {
|
|
87
|
-
linter: {
|
|
88
|
-
rules: {
|
|
89
|
-
style: {
|
|
90
|
-
noRestrictedImports: {
|
|
91
|
-
level: 'error',
|
|
92
|
-
options: {
|
|
93
|
-
paths: {
|
|
94
|
-
lodash: 'Use lodash-es',
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
someOtherKey: {
|
|
99
|
-
randomProperty: 'value',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const result = extractGlobalRuleValues(config)
|
|
107
|
-
|
|
108
|
-
// Should only extract the rule with level/options
|
|
109
|
-
expect(result.size).toBe(1)
|
|
110
|
-
expect(result.has('linter.rules.style.noRestrictedImports')).toBe(true)
|
|
111
|
-
expect(result.has('linter.rules.style.someOtherKey')).toBe(false)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
test('should not walk into arrays', () => {
|
|
115
|
-
const config = {
|
|
116
|
-
linter: {
|
|
117
|
-
rules: {
|
|
118
|
-
style: {
|
|
119
|
-
noRestrictedGlobals: {
|
|
120
|
-
level: 'error',
|
|
121
|
-
options: {
|
|
122
|
-
deniedGlobals: ['event', 'name'],
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const result = extractGlobalRuleValues(config)
|
|
131
|
-
|
|
132
|
-
expect(result.size).toBe(1)
|
|
133
|
-
expect(result.has('linter.rules.style.noRestrictedGlobals')).toBe(true)
|
|
134
|
-
|
|
135
|
-
const rule = result.get('linter.rules.style.noRestrictedGlobals')
|
|
136
|
-
expect(Array.isArray(rule.options.deniedGlobals)).toBe(true)
|
|
137
|
-
})
|
|
138
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
-
"linter": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"rules": {
|
|
6
|
-
"style": {
|
|
7
|
-
"noRestrictedImports": {
|
|
8
|
-
"level": "error",
|
|
9
|
-
"options": {
|
|
10
|
-
"patterns": [
|
|
11
|
-
{
|
|
12
|
-
"group": ["localStorage/*"],
|
|
13
|
-
"message": "Please do not import from localStorage"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"group": ["global/*"],
|
|
17
|
-
"message": "Please do not import from global"
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"overrides": [
|
|
26
|
-
{
|
|
27
|
-
"include": ["src/legacy/**"],
|
|
28
|
-
"linter": {
|
|
29
|
-
"rules": {
|
|
30
|
-
"style": {
|
|
31
|
-
"noRestrictedImports": {
|
|
32
|
-
"level": "error",
|
|
33
|
-
"options": {
|
|
34
|
-
"patterns": [
|
|
35
|
-
"__INCLUDE_GLOBAL_VALUES__",
|
|
36
|
-
{
|
|
37
|
-
"group": ["localStorage/*"],
|
|
38
|
-
"message": "Please do not import from localStorage"
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"group": ["sessionStorage/*"],
|
|
42
|
-
"message": "Please do not import from sessionStorage"
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
-
"linter": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"rules": {
|
|
6
|
-
"style": {
|
|
7
|
-
"noRestrictedImports": {
|
|
8
|
-
"level": "error",
|
|
9
|
-
"options": {
|
|
10
|
-
"paths": {
|
|
11
|
-
"lodash": "Use lodash-es instead"
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"overrides": [
|
|
19
|
-
{
|
|
20
|
-
"include": ["src/custom/**"],
|
|
21
|
-
"linter": {
|
|
22
|
-
"rules": {
|
|
23
|
-
"style": {
|
|
24
|
-
"noRestrictedImports": {
|
|
25
|
-
"level": "error",
|
|
26
|
-
"options": {
|
|
27
|
-
"paths": {
|
|
28
|
-
"react": "Custom restriction"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
]
|
|
37
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
-
"linter": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"rules": {
|
|
6
|
-
"style": {
|
|
7
|
-
"noRestrictedImports": {
|
|
8
|
-
"level": "error",
|
|
9
|
-
"options": {
|
|
10
|
-
"paths": {
|
|
11
|
-
"lodash": "Use lodash-es instead",
|
|
12
|
-
"moment": "Use date-fns instead",
|
|
13
|
-
"jquery": "No jQuery allowed"
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"overrides": [
|
|
21
|
-
{
|
|
22
|
-
"include": ["src/vendor/**"],
|
|
23
|
-
"linter": {
|
|
24
|
-
"rules": {
|
|
25
|
-
"style": {
|
|
26
|
-
"noRestrictedImports": {
|
|
27
|
-
"level": "error",
|
|
28
|
-
"options": {
|
|
29
|
-
"paths": {
|
|
30
|
-
"__INCLUDE_GLOBAL_VALUES__": true,
|
|
31
|
-
"jquery": "off",
|
|
32
|
-
"axios": "Use fetch instead"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
-
"linter": {
|
|
4
|
-
"enabled": true,
|
|
5
|
-
"rules": {
|
|
6
|
-
"style": {
|
|
7
|
-
"noRestrictedImports": {
|
|
8
|
-
"level": "error",
|
|
9
|
-
"options": {
|
|
10
|
-
"paths": {
|
|
11
|
-
"lodash": "Use lodash-es instead",
|
|
12
|
-
"moment": "Use date-fns instead"
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"noRestrictedGlobals": {
|
|
17
|
-
"level": "error",
|
|
18
|
-
"options": {
|
|
19
|
-
"deniedGlobals": ["event", "name"]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"overrides": [
|
|
26
|
-
{
|
|
27
|
-
"include": ["src/test/**"],
|
|
28
|
-
"linter": {
|
|
29
|
-
"rules": {
|
|
30
|
-
"style": {
|
|
31
|
-
"noRestrictedImports": {
|
|
32
|
-
"level": "error",
|
|
33
|
-
"options": {
|
|
34
|
-
"paths": {
|
|
35
|
-
"__INCLUDE_GLOBAL_VALUES__": true,
|
|
36
|
-
"react": "Use preact in tests"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
]
|
|
45
|
-
}
|
package/src/merger.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Merges global object values into local object values (generic first-level merge)
|
|
3
|
-
*
|
|
4
|
-
* Performs first-level merging only - merges top-level keys but does not merge
|
|
5
|
-
* nested properties within each key's value. When both global and local define
|
|
6
|
-
* the same key, the local version completely replaces the global version.
|
|
7
|
-
*
|
|
8
|
-
* Works with any object-type option (paths, deniedGlobals, elements, etc.)
|
|
9
|
-
*
|
|
10
|
-
* Special handling:
|
|
11
|
-
* - "off" values: removes that global key from the result
|
|
12
|
-
* - Local precedence: local value completely replaces global for the same key
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} globalValues - Global values from main config
|
|
15
|
-
* @param {Object} localValues - Local values from override (includes marker)
|
|
16
|
-
* @returns {Object} Merged object (marker removed)
|
|
17
|
-
*/
|
|
18
|
-
function mergeObjectValues(globalValues, localValues) {
|
|
19
|
-
const merged = {}
|
|
20
|
-
|
|
21
|
-
// Add all global keys (except those explicitly turned off or overridden)
|
|
22
|
-
for (const [key, globalValue] of Object.entries(globalValues)) {
|
|
23
|
-
const localValue = localValues[key]
|
|
24
|
-
|
|
25
|
-
// Skip if explicitly disabled
|
|
26
|
-
if (localValue === 'off') {
|
|
27
|
-
continue
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Use local value if present, otherwise use global
|
|
31
|
-
merged[key] = localValue !== undefined ? localValue : globalValue
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Add local-only keys (except marker and "off" values)
|
|
35
|
-
for (const [key, value] of Object.entries(localValues)) {
|
|
36
|
-
const shouldSkip = key === '__INCLUDE_GLOBAL_VALUES__' || key in globalValues || value === 'off'
|
|
37
|
-
if (!shouldSkip) {
|
|
38
|
-
merged[key] = value
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return merged
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Normalizes an item for comparison by sorting object keys
|
|
47
|
-
* This ensures objects with the same properties but different order are treated as equal
|
|
48
|
-
*
|
|
49
|
-
* @param {*} item - Item to normalize (object, primitive, etc.)
|
|
50
|
-
* @returns {string} Normalized JSON string representation
|
|
51
|
-
*/
|
|
52
|
-
function normalizeForComparison(item) {
|
|
53
|
-
if (typeof item !== 'object' || item === null) {
|
|
54
|
-
return JSON.stringify(item)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Sort object keys to ensure consistent serialization
|
|
58
|
-
const sortedKeys = Object.keys(item).sort()
|
|
59
|
-
const normalized = {}
|
|
60
|
-
for (const key of sortedKeys) {
|
|
61
|
-
normalized[key] = item[key]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return JSON.stringify(normalized)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Merges global array values into local array values (generic array merge)
|
|
69
|
-
*
|
|
70
|
-
* Concatenates global and local arrays, removing duplicates based on JSON serialization.
|
|
71
|
-
* Works with any array-type option (patterns, etc.)
|
|
72
|
-
*
|
|
73
|
-
* @param {Array} globalValues - Global array from main config
|
|
74
|
-
* @param {Array} localValues - Local array from override (includes marker)
|
|
75
|
-
* @returns {Array} Merged array (marker removed)
|
|
76
|
-
*/
|
|
77
|
-
function mergeArrayValues(globalValues, localValues) {
|
|
78
|
-
// Filter out marker and deduplicate local values
|
|
79
|
-
const seen = new Set()
|
|
80
|
-
const cleanLocal = []
|
|
81
|
-
|
|
82
|
-
for (const item of localValues) {
|
|
83
|
-
if (item === '__INCLUDE_GLOBAL_VALUES__') {
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const normalized = normalizeForComparison(item)
|
|
88
|
-
if (!seen.has(normalized)) {
|
|
89
|
-
seen.add(normalized)
|
|
90
|
-
cleanLocal.push(item)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Add global items that don't already exist in local
|
|
95
|
-
const newItems = globalValues.filter((item) => !seen.has(normalizeForComparison(item)))
|
|
96
|
-
|
|
97
|
-
return [...cleanLocal, ...newItems]
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
module.exports = { mergeObjectValues, mergeArrayValues }
|
package/src/merger.test.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test'
|
|
2
|
-
import { mergeArrayValues, mergeObjectValues } from './merger.js'
|
|
3
|
-
|
|
4
|
-
describe('mergeObjectValues', () => {
|
|
5
|
-
test('should merge global and local object values', () => {
|
|
6
|
-
const global = {
|
|
7
|
-
lodash: 'Use lodash-es',
|
|
8
|
-
moment: 'Use date-fns',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const local = {
|
|
12
|
-
__INCLUDE_GLOBAL_VALUES__: true,
|
|
13
|
-
react: 'Custom restriction',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const result = mergeObjectValues(global, local)
|
|
17
|
-
|
|
18
|
-
expect(result).toMatchObject({
|
|
19
|
-
lodash: 'Use lodash-es',
|
|
20
|
-
moment: 'Use date-fns',
|
|
21
|
-
react: 'Custom restriction',
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
expect(result.__INCLUDE_GLOBAL_VALUES__).toBeUndefined()
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('should prioritize local values over global', () => {
|
|
28
|
-
const global = {
|
|
29
|
-
lodash: 'Use lodash-es',
|
|
30
|
-
moment: 'Use date-fns',
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const local = {
|
|
34
|
-
__INCLUDE_GLOBAL_VALUES__: true,
|
|
35
|
-
lodash: 'Lodash is fine actually',
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const result = mergeObjectValues(global, local)
|
|
39
|
-
|
|
40
|
-
expect(result.lodash).toBe('Lodash is fine actually')
|
|
41
|
-
expect(result.moment).toBe('Use date-fns')
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
test('should handle "off" overrides', () => {
|
|
45
|
-
const global = {
|
|
46
|
-
lodash: 'Use lodash-es',
|
|
47
|
-
moment: 'Use date-fns',
|
|
48
|
-
jquery: 'No jQuery',
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const local = {
|
|
52
|
-
__INCLUDE_GLOBAL_VALUES__: true,
|
|
53
|
-
jquery: 'off',
|
|
54
|
-
react: 'Custom restriction',
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const result = mergeObjectValues(global, local)
|
|
58
|
-
|
|
59
|
-
expect(result.lodash).toBe('Use lodash-es')
|
|
60
|
-
expect(result.moment).toBe('Use date-fns')
|
|
61
|
-
expect(result.jquery).toBeUndefined()
|
|
62
|
-
expect(result.react).toBe('Custom restriction')
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('should remove marker from result', () => {
|
|
66
|
-
const global = {
|
|
67
|
-
lodash: 'Use lodash-es',
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const local = {
|
|
71
|
-
__INCLUDE_GLOBAL_VALUES__: true,
|
|
72
|
-
react: 'Custom restriction',
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const result = mergeObjectValues(global, local)
|
|
76
|
-
|
|
77
|
-
expect(result.__INCLUDE_GLOBAL_VALUES__).toBeUndefined()
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test('should handle empty global object', () => {
|
|
81
|
-
const global = {}
|
|
82
|
-
|
|
83
|
-
const local = {
|
|
84
|
-
__INCLUDE_GLOBAL_VALUES__: true,
|
|
85
|
-
react: 'Custom restriction',
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const result = mergeObjectValues(global, local)
|
|
89
|
-
|
|
90
|
-
expect(result).toMatchObject({
|
|
91
|
-
react: 'Custom restriction',
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('should handle empty local object (except marker)', () => {
|
|
96
|
-
const global = {
|
|
97
|
-
lodash: 'Use lodash-es',
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const local = {
|
|
101
|
-
__INCLUDE_GLOBAL_VALUES__: true,
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const result = mergeObjectValues(global, local)
|
|
105
|
-
|
|
106
|
-
expect(result).toMatchObject({
|
|
107
|
-
lodash: 'Use lodash-es',
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
describe('mergeArrayValues', () => {
|
|
113
|
-
test('should merge global and local arrays', () => {
|
|
114
|
-
const global = ['event', 'name', 'global']
|
|
115
|
-
const local = ['__INCLUDE_GLOBAL_VALUES__', 'localStorage', 'sessionStorage']
|
|
116
|
-
|
|
117
|
-
const result = mergeArrayValues(global, local)
|
|
118
|
-
|
|
119
|
-
expect(result).toEqual(['localStorage', 'sessionStorage', 'event', 'name', 'global'])
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('should deduplicate merged arrays', () => {
|
|
123
|
-
const global = ['event', 'name', 'global']
|
|
124
|
-
const local = ['__INCLUDE_GLOBAL_VALUES__', 'event', 'localStorage']
|
|
125
|
-
|
|
126
|
-
const result = mergeArrayValues(global, local)
|
|
127
|
-
|
|
128
|
-
// Should not have duplicates
|
|
129
|
-
expect(result.filter((x) => x === 'event')).toHaveLength(1)
|
|
130
|
-
|
|
131
|
-
// Should maintain local precedence (local items first)
|
|
132
|
-
expect(result).toEqual(['event', 'localStorage', 'name', 'global'])
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
test('should remove marker from result', () => {
|
|
136
|
-
const global = ['event', 'name']
|
|
137
|
-
const local = ['__INCLUDE_GLOBAL_VALUES__', 'localStorage']
|
|
138
|
-
|
|
139
|
-
const result = mergeArrayValues(global, local)
|
|
140
|
-
|
|
141
|
-
expect(result).not.toContain('__INCLUDE_GLOBAL_VALUES__')
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
test('should handle empty global array', () => {
|
|
145
|
-
const global = []
|
|
146
|
-
const local = ['__INCLUDE_GLOBAL_VALUES__', 'localStorage']
|
|
147
|
-
|
|
148
|
-
const result = mergeArrayValues(global, local)
|
|
149
|
-
|
|
150
|
-
expect(result).toEqual(['localStorage'])
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
test('should handle local array with only marker', () => {
|
|
154
|
-
const global = ['event', 'name']
|
|
155
|
-
const local = ['__INCLUDE_GLOBAL_VALUES__']
|
|
156
|
-
|
|
157
|
-
const result = mergeArrayValues(global, local)
|
|
158
|
-
|
|
159
|
-
expect(result).toEqual(['event', 'name'])
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
test('should deduplicate complex objects', () => {
|
|
163
|
-
const global = [{ path: 'lodash', message: 'Use lodash-es' }]
|
|
164
|
-
const local = [
|
|
165
|
-
'__INCLUDE_GLOBAL_VALUES__',
|
|
166
|
-
{ path: 'lodash', message: 'Use lodash-es' },
|
|
167
|
-
{ path: 'moment', message: 'Use date-fns' },
|
|
168
|
-
{ message: 'Use date-fns', path: 'moment' },
|
|
169
|
-
]
|
|
170
|
-
|
|
171
|
-
const result = mergeArrayValues(global, local)
|
|
172
|
-
|
|
173
|
-
// Should deduplicate based on JSON serialization
|
|
174
|
-
expect(result).toHaveLength(2)
|
|
175
|
-
expect(result[0]).toMatchObject({ path: 'lodash', message: 'Use lodash-es' })
|
|
176
|
-
expect(result[1]).toMatchObject({ path: 'moment', message: 'Use date-fns' })
|
|
177
|
-
})
|
|
178
|
-
})
|