LintConfig - bhsd-harry/wikiparser-node GitHub Wiki

This is an internal document. For visitors, you can now go back to the home page.

// validateConfigValue
var {lintConfig: {rules}} = Parser;
rules.h1 = 0;
assert.strictEqual(rules.getSeverity('h1'), false);
rules.h1 = 'off';
assert.strictEqual(rules.getSeverity('h1'), false);
rules.h1 = false;
assert.strictEqual(rules.getSeverity('h1'), false);
rules.h1 = 1;
assert.strictEqual(rules.getSeverity('h1'), 'warning');
rules.h1 = 'warning';
assert.strictEqual(rules.getSeverity('h1'), 'warning');
rules.h1 = 2;
assert.strictEqual(rules.getSeverity('h1'), 'error');
rules.h1 = 'error';
assert.strictEqual(rules.getSeverity('h1'), 'error');
rules.h1 = [1];
assert.strictEqual(rules.getSeverity('h1'), 'warning');
rules.h1 = ['warning'];
assert.strictEqual(rules.getSeverity('h1'), 'warning');
rules.h1 = [2, {}];
assert.strictEqual(rules.getSeverity('h1'), 'error');
rules.h1 = ['error', {test: 'off'}];
assert.strictEqual(rules.getSeverity('h1'), 'error');
assert.strictEqual(rules.getSeverity('h1', 'test'), false);
// legacy config
Parser.lintConfig = {h1: 2};
assert.strictEqual(Parser.lintConfig.rules.getSeverity('h1'), 'error');
assert.ok(Parser.lintConfig.computeEditInfo);
assert.ok(Parser.lintConfig.fix);
assert.ok(!Parser.lintConfig.ignoreDisables);
assert.strictEqual(Parser.lintConfig.configurationComment, 'lint');
// computeEditInfo
var error1 = {
		rule: 'no-ignored',
		severity: 'error',
		message: 'invalid conversion flag',
		startLine: 0,
		startCol: 2,
		startIndex: 2,
		endLine: 0,
		endCol: 3,
		endIndex: 3,
	},
	error2 = {
		rule: 'illegal-attr',
		severity: 'error',
		message: 'invalid attribute name',
		startLine: 0,
		startCol: 4,
		startIndex: 4,
		endLine: 0,
		endCol: 8,
		endIndex: 8,
	};
assert.deepStrictEqual(
	Parser.parse('-{a|}-').lint(),
	Object.assign(
		[
			{
				...error1,
				fix: {
					desc: 'uppercase',
					range: [2, 3],
					text: 'A',
				},
			},
		],
		{output: '-{A|}-'},
	),
);
assert.deepStrictEqual(
	Parser.parse('<br attr>').lint(),
	[
		{
			...error2,
			suggestions: [
				{
					desc: 'remove',
					range: [4, 8],
					text: '',
				},
			],
		},
	],
);
Parser.lintConfig.computeEditInfo = false;
assert.deepStrictEqual(
	Parser.parse('-{a|}-').lint(),
	Object.assign([error1], {output: '-{A|}-'}),
);
assert.deepStrictEqual(
	Parser.parse('<br attr>').lint(),
	[error2],
);
// fix
var error = {
	rule: 'unmatched-tag',
	severity: 'error',
	message: 'tag that is both closing and self-closing',
	startLine: 0,
	startCol: 0,
	startIndex: 0,
	endLine: 0,
	endCol: 5,
	endIndex: 5,
	fix: {
		desc: 'open',
		range: [1, 2],
		text: '',
	},
};
assert.deepStrictEqual(
	Parser.parse('</br>').lint(),
	Object.assign([error], {output: '<br>'}),
);
Parser.lintConfig.fix = false;
assert.deepStrictEqual(
	Parser.parse('</br>').lint(),
	[error],
);
// ignoreDisables
var error = {
	rule: 'tag-like',
	severity: 'error',
	message: 'lonely "<"',
	startLine: 0,
	startCol: 1,
	startIndex: 1,
	endLine: 0,
	endCol: 3,
	endIndex: 3,
	suggestions: [
		{
			desc: 'escape',
			range: [1, 2],
			text: '&lt;',
		},
	],
};
assert.deepStrictEqual(
	Parser.parse('a<b <!-- lint-disable-line -->').lint(),
	[],
);
Parser.lintConfig.ignoreDisables = true;
assert.deepStrictEqual(
	Parser.parse('a<b <!-- lint-disable-line -->').lint(),
	[error],
);
// configurationComment
var error = {
	rule: 'lonely-http',
	severity: 'warning',
	message: 'lonely "http://"',
	startLine: 0,
	startCol: 0,
	startIndex: 0,
	endLine: 0,
	endCol: 7,
	endIndex: 7,
};
assert.deepStrictEqual(
	Parser.parse('http:// <!-- wikilint-disable-line -->').lint(),
	[error],
);
Parser.lintConfig.configurationComment = 'wikilint';
assert.deepStrictEqual(
	Parser.parse('http:// <!-- wikilint-disable-line -->').lint(),
	[],
);
⚠️ **GitHub.com Fallback** ⚠️