lint(tests): clean up magic numbers
This commit is contained in:
parent
e773c1ce5c
commit
4f1571b75c
|
@ -212,29 +212,9 @@
|
||||||
"error",
|
"error",
|
||||||
{
|
{
|
||||||
"ignore": [
|
"ignore": [
|
||||||
-3,
|
|
||||||
-2,
|
|
||||||
-1,
|
|
||||||
0,
|
0,
|
||||||
1,
|
1,
|
||||||
2,
|
10
|
||||||
3,
|
|
||||||
4,
|
|
||||||
5,
|
|
||||||
6,
|
|
||||||
7,
|
|
||||||
8,
|
|
||||||
9,
|
|
||||||
10,
|
|
||||||
20,
|
|
||||||
30,
|
|
||||||
40,
|
|
||||||
50,
|
|
||||||
60,
|
|
||||||
70,
|
|
||||||
80,
|
|
||||||
90,
|
|
||||||
100
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -344,7 +324,6 @@
|
||||||
true,
|
true,
|
||||||
"check-multiline-start"
|
"check-multiline-start"
|
||||||
],
|
],
|
||||||
"no-boolean-literal-compare": true,
|
|
||||||
"no-dynamic-delete": true,
|
"no-dynamic-delete": true,
|
||||||
"no-inferred-empty-object-type": true,
|
"no-inferred-empty-object-type": true,
|
||||||
"no-reference-import": true,
|
"no-reference-import": true,
|
||||||
|
|
|
@ -10,12 +10,13 @@ import { readSource, writeSource } from './source';
|
||||||
import { VERSION_INFO } from './version';
|
import { VERSION_INFO } from './version';
|
||||||
import { VisitorContext } from './visitor/VisitorContext';
|
import { VisitorContext } from './visitor/VisitorContext';
|
||||||
|
|
||||||
|
const ARGS_START = 2;
|
||||||
export const STATUS_SUCCESS = 0;
|
export const STATUS_SUCCESS = 0;
|
||||||
export const STATUS_ERROR = 1;
|
export const STATUS_ERROR = 1;
|
||||||
export const STATUS_MAX = 255;
|
export const STATUS_MAX = 255;
|
||||||
|
|
||||||
export async function main(argv: Array<string>): Promise<number> {
|
export async function main(argv: Array<string>): Promise<number> {
|
||||||
const { args, mode } = await parseArgs(argv.slice(2));
|
const { args, mode } = await parseArgs(argv.slice(ARGS_START));
|
||||||
if (mode === MODE.complete) {
|
if (mode === MODE.complete) {
|
||||||
showCompletionScript();
|
showCompletionScript();
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
|
|
|
@ -200,13 +200,13 @@ export async function resolveRules(rules: Array<Rule>, selector: RuleSelector):
|
||||||
for (const r of rules) {
|
for (const r of rules) {
|
||||||
let active = false;
|
let active = false;
|
||||||
|
|
||||||
|
const includedTags = intersection(selector.includeTag, r.tags);
|
||||||
active = active || selector.includeLevel.includes(r.level);
|
active = active || selector.includeLevel.includes(r.level);
|
||||||
active = active || selector.includeName.includes(r.name);
|
active = active || selector.includeName.includes(r.name);
|
||||||
const includedTags = intersection(selector.includeTag, r.tags);
|
|
||||||
active = active || includedTags.length > 0;
|
active = active || includedTags.length > 0;
|
||||||
|
|
||||||
active = active && (!selector.excludeLevel.includes(r.level));
|
active = active && (selector.excludeLevel.includes(r.level) === false);
|
||||||
active = active && (!selector.excludeName.includes(r.name));
|
active = active && (selector.excludeName.includes(r.name) === false);
|
||||||
const excludedTags = intersection(selector.excludeTag, r.tags);
|
const excludedTags = intersection(selector.excludeTag, r.tags);
|
||||||
active = active && (excludedTags.length === 0);
|
active = active && (excludedTags.length === 0);
|
||||||
|
|
||||||
|
|
|
@ -127,9 +127,12 @@ describeLeaks('main app', async () => {
|
||||||
it('should validate config before running', async () => {
|
it('should validate config before running', async () => {
|
||||||
mockFs(TEST_FILES);
|
mockFs(TEST_FILES);
|
||||||
|
|
||||||
|
const [configPath, configDocs, configName] = TEST_ARGS_CONFIG;
|
||||||
const status = await main([
|
const status = await main([
|
||||||
...TEST_ARGS_PRE,
|
...TEST_ARGS_PRE,
|
||||||
...TEST_ARGS_CONFIG.slice(0, 3),
|
configPath,
|
||||||
|
configDocs,
|
||||||
|
configName,
|
||||||
'partial.yml',
|
'partial.yml',
|
||||||
...TEST_ARGS_RULES,
|
...TEST_ARGS_RULES,
|
||||||
...TEST_ARGS_SOURCE,
|
...TEST_ARGS_SOURCE,
|
||||||
|
|
|
@ -22,7 +22,8 @@ bar: {}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
expect(Array.isArray(data)).to.equal(true);
|
expect(Array.isArray(data)).to.equal(true);
|
||||||
expect(data.length).to.equal(2);
|
const EXPECTED_DOCS = 2;
|
||||||
|
expect(data.length).to.equal(EXPECTED_DOCS);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -164,7 +164,8 @@ describeLeaks('load rule path helper', async () => {
|
||||||
|
|
||||||
mockFS.restore();
|
mockFS.restore();
|
||||||
|
|
||||||
expect(rules.length).to.equal(2);
|
const EXPECTED_RULES = 2;
|
||||||
|
expect(rules.length).to.equal(EXPECTED_RULES);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -223,7 +224,8 @@ describeLeaks('load rule module helper', async () => {
|
||||||
$ref: 'test-rules#/definitions/foo',
|
$ref: 'test-rules#/definitions/foo',
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(schema(2)).to.equal(false);
|
const NUMBER_VALUE = 2;
|
||||||
|
expect(schema(NUMBER_VALUE)).to.equal(false);
|
||||||
expect(schema('foo')).to.equal(true);
|
expect(schema('foo')).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,10 @@ describeLeaks('rule resolver', async () => {
|
||||||
includeLevel: [LogLevel.Warn],
|
includeLevel: [LogLevel.Warn],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(info.length).to.equal(2);
|
const EXPECTED_RULES = 2;
|
||||||
|
expect(info.length).to.equal(EXPECTED_RULES);
|
||||||
expect(info[0]).to.equal(TEST_RULES[1]);
|
expect(info[0]).to.equal(TEST_RULES[1]);
|
||||||
|
/* eslint-disable-next-line no-magic-numbers */
|
||||||
expect(info[1]).to.equal(TEST_RULES[2]);
|
expect(info[1]).to.equal(TEST_RULES[2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -68,8 +70,10 @@ describeLeaks('rule resolver', async () => {
|
||||||
includeTag: ['test'],
|
includeTag: ['test'],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(rules.length).to.equal(2);
|
const EXPECTED_RULES = 2;
|
||||||
|
expect(rules.length).to.equal(EXPECTED_RULES);
|
||||||
expect(rules[0]).to.equal(TEST_RULES[1]);
|
expect(rules[0]).to.equal(TEST_RULES[1]);
|
||||||
|
/* eslint-disable-next-line no-magic-numbers */
|
||||||
expect(rules[1]).to.equal(TEST_RULES[2]);
|
expect(rules[1]).to.equal(TEST_RULES[2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -81,8 +85,10 @@ describeLeaks('rule resolver', async () => {
|
||||||
includeTag: ['all'],
|
includeTag: ['all'],
|
||||||
}));
|
}));
|
||||||
|
|
||||||
expect(rules.length).to.equal(2);
|
const EXPECTED_RULES = 2;
|
||||||
|
expect(rules.length).to.equal(EXPECTED_RULES);
|
||||||
expect(rules[0]).to.equal(TEST_RULES[1]);
|
expect(rules[0]).to.equal(TEST_RULES[1]);
|
||||||
|
/* eslint-disable-next-line no-magic-numbers */
|
||||||
expect(rules[1]).to.equal(TEST_RULES[2]);
|
expect(rules[1]).to.equal(TEST_RULES[2]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -91,7 +91,7 @@ describeLeaks('rule visitor', async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const data = {
|
const data = {
|
||||||
foo: [1, 2, 3],
|
foo: [Math.random(), Math.random(), Math.random()],
|
||||||
};
|
};
|
||||||
const rule = new SchemaRule({
|
const rule = new SchemaRule({
|
||||||
check: {},
|
check: {},
|
||||||
|
@ -114,7 +114,7 @@ describeLeaks('rule visitor', async () => {
|
||||||
await visitor.visit(ctx, data);
|
await visitor.visit(ctx, data);
|
||||||
|
|
||||||
expect(pickSpy).to.have.callCount(1).and.to.have.been.calledWithExactly(ctx, data);
|
expect(pickSpy).to.have.callCount(1).and.to.have.been.calledWithExactly(ctx, data);
|
||||||
expect(visitStub).to.have.callCount(3);
|
expect(visitStub).to.have.callCount(data.foo.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
itLeaks('should visit individual items', async () => {
|
itLeaks('should visit individual items', async () => {
|
||||||
|
@ -127,7 +127,7 @@ describeLeaks('rule visitor', async () => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const data = {
|
const data = {
|
||||||
foo: [1, 2, 3],
|
foo: [Math.random(), Math.random(), Math.random()],
|
||||||
};
|
};
|
||||||
const rule = new SchemaRule({
|
const rule = new SchemaRule({
|
||||||
check: {},
|
check: {},
|
||||||
|
@ -152,8 +152,9 @@ describeLeaks('rule visitor', async () => {
|
||||||
});
|
});
|
||||||
await visitor.visit(ctx, data);
|
await visitor.visit(ctx, data);
|
||||||
|
|
||||||
expect(visitStub).to.have.callCount(3);
|
const EXPECTED_VISITS = 3;
|
||||||
expect(ctx.errors.length).to.equal(3);
|
expect(visitStub).to.have.callCount(EXPECTED_VISITS);
|
||||||
|
expect(ctx.errors.length).to.equal(EXPECTED_VISITS);
|
||||||
});
|
});
|
||||||
|
|
||||||
itLeaks('should not pick items', async () => {
|
itLeaks('should not pick items', async () => {
|
||||||
|
|
|
@ -113,7 +113,7 @@ describeLeaks('schema rule', async () => {
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
const results = await rule.pick(ctx, {
|
const results = await rule.pick(ctx, {
|
||||||
foo: [1, 2, 3],
|
foo: [Math.random(), Math.random(), Math.random()],
|
||||||
});
|
});
|
||||||
expect(Array.isArray(results)).to.equal(true);
|
expect(Array.isArray(results)).to.equal(true);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue