1
0
Fork 0

lint(tests): clean up magic numbers

This commit is contained in:
ssube 2019-11-19 06:03:48 -06:00
parent e773c1ce5c
commit 4f1571b75c
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
9 changed files with 32 additions and 39 deletions

View File

@ -212,29 +212,9 @@
"error",
{
"ignore": [
-3,
-2,
-1,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
20,
30,
40,
50,
60,
70,
80,
90,
100
10
]
}
],
@ -344,7 +324,6 @@
true,
"check-multiline-start"
],
"no-boolean-literal-compare": true,
"no-dynamic-delete": true,
"no-inferred-empty-object-type": true,
"no-reference-import": true,

View File

@ -10,12 +10,13 @@ import { readSource, writeSource } from './source';
import { VERSION_INFO } from './version';
import { VisitorContext } from './visitor/VisitorContext';
const ARGS_START = 2;
export const STATUS_SUCCESS = 0;
export const STATUS_ERROR = 1;
export const STATUS_MAX = 255;
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) {
showCompletionScript();
return STATUS_SUCCESS;

View File

@ -200,13 +200,13 @@ export async function resolveRules(rules: Array<Rule>, selector: RuleSelector):
for (const r of rules) {
let active = false;
const includedTags = intersection(selector.includeTag, r.tags);
active = active || selector.includeLevel.includes(r.level);
active = active || selector.includeName.includes(r.name);
const includedTags = intersection(selector.includeTag, r.tags);
active = active || includedTags.length > 0;
active = active && (!selector.excludeLevel.includes(r.level));
active = active && (!selector.excludeName.includes(r.name));
active = active && (selector.excludeLevel.includes(r.level) === false);
active = active && (selector.excludeName.includes(r.name) === false);
const excludedTags = intersection(selector.excludeTag, r.tags);
active = active && (excludedTags.length === 0);

View File

@ -127,9 +127,12 @@ describeLeaks('main app', async () => {
it('should validate config before running', async () => {
mockFs(TEST_FILES);
const [configPath, configDocs, configName] = TEST_ARGS_CONFIG;
const status = await main([
...TEST_ARGS_PRE,
...TEST_ARGS_CONFIG.slice(0, 3),
configPath,
configDocs,
configName,
'partial.yml',
...TEST_ARGS_RULES,
...TEST_ARGS_SOURCE,

View File

@ -22,7 +22,8 @@ bar: {}
`);
expect(Array.isArray(data)).to.equal(true);
expect(data.length).to.equal(2);
const EXPECTED_DOCS = 2;
expect(data.length).to.equal(EXPECTED_DOCS);
});
});
});

View File

@ -164,7 +164,8 @@ describeLeaks('load rule path helper', async () => {
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',
});
expect(schema(2)).to.equal(false);
const NUMBER_VALUE = 2;
expect(schema(NUMBER_VALUE)).to.equal(false);
expect(schema('foo')).to.equal(true);
});

View File

@ -45,8 +45,10 @@ describeLeaks('rule resolver', async () => {
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]);
/* eslint-disable-next-line no-magic-numbers */
expect(info[1]).to.equal(TEST_RULES[2]);
});
});
@ -68,8 +70,10 @@ describeLeaks('rule resolver', async () => {
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]);
/* eslint-disable-next-line no-magic-numbers */
expect(rules[1]).to.equal(TEST_RULES[2]);
});
});
@ -81,8 +85,10 @@ describeLeaks('rule resolver', async () => {
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]);
/* eslint-disable-next-line no-magic-numbers */
expect(rules[1]).to.equal(TEST_RULES[2]);
});
});

View File

@ -91,7 +91,7 @@ describeLeaks('rule visitor', async () => {
},
});
const data = {
foo: [1, 2, 3],
foo: [Math.random(), Math.random(), Math.random()],
};
const rule = new SchemaRule({
check: {},
@ -114,7 +114,7 @@ describeLeaks('rule visitor', async () => {
await visitor.visit(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 () => {
@ -127,7 +127,7 @@ describeLeaks('rule visitor', async () => {
},
});
const data = {
foo: [1, 2, 3],
foo: [Math.random(), Math.random(), Math.random()],
};
const rule = new SchemaRule({
check: {},
@ -152,8 +152,9 @@ describeLeaks('rule visitor', async () => {
});
await visitor.visit(ctx, data);
expect(visitStub).to.have.callCount(3);
expect(ctx.errors.length).to.equal(3);
const EXPECTED_VISITS = 3;
expect(visitStub).to.have.callCount(EXPECTED_VISITS);
expect(ctx.errors.length).to.equal(EXPECTED_VISITS);
});
itLeaks('should not pick items', async () => {

View File

@ -113,7 +113,7 @@ describeLeaks('schema rule', async () => {
tags: [],
});
const results = await rule.pick(ctx, {
foo: [1, 2, 3],
foo: [Math.random(), Math.random(), Math.random()],
});
expect(Array.isArray(results)).to.equal(true);
});