Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to improve types for named-grid-areas-no-invalid rule #5513

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/rules/named-grid-areas-no-invalid/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

'use strict';

const declarationValueIndex = require('../../utils/declarationValueIndex');
Expand All @@ -18,9 +16,10 @@ const messages = ruleMessages(ruleName, {
expectedRectangle: (name) => `Expected single filled-in rectangle for "${name}"`,
});

function rule(actual) {
/** @type {import('stylelint').StylelintRule} */
const rule = (primary) => {
return (root, result) => {
const validOptions = validateOptions(result, ruleName, { actual });
const validOptions = validateOptions(result, ruleName, { actual: primary });

if (!validOptions) {
return;
Expand All @@ -31,6 +30,7 @@ function rule(actual) {

if (value.toLowerCase().trim() === 'none') return;

/** @type {string[][]} */
const areas = [];
let reportSent = false;

Expand Down Expand Up @@ -66,6 +66,10 @@ function rule(actual) {
complain(messages.expectedRectangle(name));
});

/**
* @param {string} message
* @param {number} [sourceIndex=0]
*/
function complain(message, sourceIndex = 0) {
report({
message,
Expand All @@ -77,7 +81,7 @@ function rule(actual) {
}
});
};
}
};

rule.ruleName = ruleName;
rule.messages = messages;
Expand Down