Skip to content

Commit

Permalink
test: only check references of same key rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick-Remy authored and mightyiam committed May 25, 2020
1 parent 7edcc5c commit 712c2f7
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test, { ExecutionContext } from 'ava'
import test from 'ava'
import exported from '.'
import { rules as standardRules } from 'eslint-config-standard/eslintrc.json'
import standardPkg from 'eslint-config-standard/package.json'
Expand Down Expand Up @@ -198,27 +198,15 @@ interface RulesConfig {
[name: string]: object | string | number | boolean | null
}

/**
* Test that objects' values do not hold same memory references
*/
function testNotHaveObjectReferences (t: ExecutionContext<unknown>, rules: RulesConfig, comparisonRules: RulesConfig, skipSameKey: boolean = false): void {
for (const ruleName in rules) {
const ruleConfig = rules[ruleName]
if (typeof ruleConfig !== 'object') continue // Non-objects use copy-by-value
test('No references to standard rules config', (t) => {
for (const override of exported.overrides) {
const standardRulesConfig: RulesConfig = standardRules
const overrideRulesConfig: RulesConfig = override.rules

for (const comparisonRuleName in comparisonRules) {
if (skipSameKey && ruleName === comparisonRuleName) continue
t.not(ruleConfig, comparisonRules[comparisonRuleName])
}
}
}
for (const ruleName in standardRulesConfig) {
if (typeof standardRulesConfig[ruleName] !== 'object') continue // Non-objects use copy-by-value

test('No references in rules config', (t) => {
for (const override of exported.overrides) {
const rules: RulesConfig = override.rules
// Rules must not have object references inside theirselves
testNotHaveObjectReferences(t, rules, rules, true)
// Rules must not have object references to standard rules
testNotHaveObjectReferences(t, rules, standardRules)
t.not(overrideRulesConfig[`@typescript-eslint/${ruleName}`], standardRulesConfig[ruleName])
}
}
})

0 comments on commit 712c2f7

Please sign in to comment.