build(lint): use native stylelint config resolution (#350)

Co-authored-by: winston <[email protected]>
This commit is contained in:
uncenterandwinston authored and GitHub committed 2023-11-21 08:32:25 +01:00
1 parent 493eab7f11
commit c7344a51ba
5 files changed
+194 -189

No files matched your search

+170
View File
@@ -0,0 +1,170 @@
/**
* @type {import('npm:stylelint').Config}
*/
const config = {
extends: "stylelint-config-standard",
customSyntax: "postcss-less",
rules: {
"selector-class-pattern": null,
"custom-property-pattern": null,
"selector-id-pattern": null,
"rule-empty-line-before": null,
"comment-empty-line-before": null,
"custom-property-empty-line-before": null,
"at-rule-empty-line-before": null,
"declaration-empty-line-before": null,
"property-no-vendor-prefix": null,
"alpha-value-notation": null,
"color-function-notation": null,
"hue-degree-notation": null,
// Needed for Stylus v1.5.35 workaround, see #341
"media-feature-range-notation": "prefix",
// These are not invalid with Less.
"no-invalid-position-at-import-rule": null,
"no-invalid-double-slash-comments": null,
"at-rule-disallowed-list": [
["/^font.*/"],
{
/**
* @param {string} atRule
*/
message: (atRule) =>
`At-rule ${atRule} is not allowed in Catppuccin userstyles`,
},
],
"property-disallowed-list": [
[
// Disallow setting custom fonts.
"/font.*/",
// Ideally we could disallow these, but CSS continues to be gross.
// "/animation.*/",
// "/transition.*/",
// Prefer `border-color` over `border`, `outline-color` over `outline`, etc.
"border",
"outline",
],
{
/**
* @param {string} prop
*/
message: (prop) => {
if (["border", "outline"].includes(prop)) {
return `Use \`${prop}-color\` instead of \`${prop}\``;
} else {
return `Property \`${prop}\` is not allowed in Catppuccin userstyles`;
}
},
},
],
"function-no-unknown": [
true,
{
ignoreFunctions: [
// Generated from https://lesscss.org/functions/ via `Array.from(document.querySelectorAll('.section-content h3.docs-heading'), heading => heading.textContent.replace('\n', ''))`.
"%",
"abs",
"acos",
"alpha",
"argb",
"asin",
"atan",
"average",
"blue",
"boolean",
"ceil",
"color",
"contrast",
"convert",
"cos",
"darken",
"data-uri",
"default",
"desaturate",
"difference",
"e",
"each",
"escape",
"exclusion",
"extract",
"fade",
"fadein",
"fadeout",
"floor",
"get-unit",
"green",
"greyscale",
"hardlight",
"hsl",
"hsla",
"hsv",
"hsva",
"hsvhue",
"hsvsaturation",
"hsvvalue",
"hue",
"if",
"image-height",
"image-size",
"image-width",
"iscolor",
"isdefined",
"isem",
"iskeyword",
"isnumber",
"ispercentage",
"ispixel",
"isruleset",
"isstring",
"isunit",
"isurl",
"length",
"lighten",
"lightness",
"luma",
"luminance",
"max",
"min",
"mix",
"mod",
"multiply",
"negation",
"overlay",
"percentage",
"pi",
"pow",
"range",
"red",
"replace",
"rgb",
"rgba",
"round",
"saturate",
"saturation",
"screen",
"shade",
"sin",
"softlight",
"spin",
"sqrt",
"svg-gradient",
"tan",
"tint",
"unit",
],
},
],
"function-name-case": null,
"no-descending-specificity": null,
},
};
module.exports = config;
+2 -1
View File
@@ -16,5 +16,6 @@
"lint": "deno run -A ./scripts/lint/main.ts",
"lint:fix": "deno task lint --fix",
"update-types": "deno run -A ./scripts/update-types.ts"
}
},
"nodeModulesDir": true
}
Generated
+11 -13
View File
@@ -1483,17 +1483,6 @@
}
},
"remote": {
"https://deno.land/[email protected]/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74",
"https://deno.land/[email protected]/_util/os.ts": "3b4c6e27febd119d36a416d7a97bd3b0251b77c88942c8f16ee5953ea13e2e49",
"https://deno.land/[email protected]/path/_constants.ts": "df1db3ffa6dd6d1252cc9617e5d72165cd2483df90e93833e13580687b6083c3",
"https://deno.land/[email protected]/path/_interface.ts": "ee3b431a336b80cf445441109d089b70d87d5e248f4f90ff906820889ecf8d09",
"https://deno.land/[email protected]/path/_util.ts": "c1e9686d0164e29f7d880b2158971d805b6e0efc3110d0b3e24e4b8af2190d2b",
"https://deno.land/[email protected]/path/common.ts": "bee563630abd2d97f99d83c96c2fa0cca7cee103e8cb4e7699ec4d5db7bd2633",
"https://deno.land/[email protected]/path/glob.ts": "cb5255638de1048973c3e69e420c77dc04f75755524cb3b2e160fe9277d939ee",
"https://deno.land/[email protected]/path/mod.ts": "4945b430b759b0b3d98f2a278542cbcf95e0ad2bd8eaaed3c67322b306b2b346",
"https://deno.land/[email protected]/path/posix.ts": "c1f7afe274290ea0b51da07ee205653b2964bd74909a82deb07b69a6cc383aaa",
"https://deno.land/[email protected]/path/separator.ts": "fe1816cb765a8068afb3e8f13ad272351c85cbc739af56dacfc7d93d710fe0f9",
"https://deno.land/[email protected]/path/win32.ts": "bd7549042e37879c68ff2f8576a25950abbfca1d696d41d82c7bca0b7e6f452c",
"https://deno.land/[email protected]/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9",
"https://deno.land/[email protected]/assert/_diff.ts": "58e1461cc61d8eb1eacbf2a010932bf6a05b79344b02ca38095f9b805795dc48",
"https://deno.land/[email protected]/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7",
@@ -1525,13 +1514,21 @@
"https://deno.land/[email protected]/assert/mod.ts": "37c49a26aae2b254bbe25723434dc28cd7532e444cf0b481a97c045d110ec085",
"https://deno.land/[email protected]/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a",
"https://deno.land/[email protected]/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536",
"https://deno.land/[email protected]/collections/_utils.ts": "5114abc026ddef71207a79609b984614e66a63a4bda17d819d56b0e72c51527e",
"https://deno.land/[email protected]/collections/deep_merge.ts": "9db788ba56cb05b65c77166b789e58e125dff159b7f41bf4d19dc1cba19ecb8b",
"https://deno.land/[email protected]/flags/mod.ts": "0948466fc437f017f00c0b972a422b3dc3317a790bcf326429d23182977eaf9f",
"https://deno.land/[email protected]/fmt/colors.ts": "c51c4642678eb690dcf5ffee5918b675bf01a33fba82acf303701ae1a4f8c8d9",
"https://deno.land/[email protected]/fmt/printf.ts": "b4ca7dc4b2323b2614c7d11b3e6dc80442e5d56c33665cdf9b9de0dabb80f9ec",
"https://deno.land/[email protected]/fs/_util.ts": "fbf57dcdc9f7bc8128d60301eece608246971a7836a3bb1e78da75314f08b978",
"https://deno.land/[email protected]/fs/copy.ts": "ca19e4837965914471df38fbd61e16f9e8adfe89f9cffb0c83615c83ea3fc2bf",
"https://deno.land/[email protected]/fs/empty_dir.ts": "0b4a2508232446eed232ad1243dd4b0f07ac503a281633ae1324d1528df70964",
"https://deno.land/[email protected]/fs/ensure_dir.ts": "dc64c4c75c64721d4e3fb681f1382f803ff3d2868f08563ff923fdd20d071c40",
"https://deno.land/[email protected]/fs/ensure_file.ts": "39ac83cc283a20ec2735e956adf5de3e8a3334e0b6820547b5772f71c49ae083",
"https://deno.land/[email protected]/fs/ensure_link.ts": "c15e69c48556d78aae31b83e0c0ece04b7b8bc0951412f5b759aceb6fde7f0ac",
"https://deno.land/[email protected]/fs/ensure_symlink.ts": "b389c8568f0656d145ac7ece472afe710815cccbb2ebfd19da7978379ae143fe",
"https://deno.land/[email protected]/fs/eol.ts": "f1f2eb348a750c34500741987b21d65607f352cf7205f48f4319d417fff42842",
"https://deno.land/[email protected]/fs/exists.ts": "cb59a853d84871d87acab0e7936a4dac11282957f8e195102c5a7acb42546bb8",
"https://deno.land/[email protected]/fs/expand_glob.ts": "4f98c508fc9e40d6311d2f7fd88aaad05235cc506388c22dda315e095305811d",
"https://deno.land/[email protected]/fs/mod.ts": "bc3d0acd488cc7b42627044caf47d72019846d459279544e1934418955ba4898",
"https://deno.land/[email protected]/fs/move.ts": "b4f8f46730b40c32ea3c0bc8eb0fd0e8139249a698883c7b3756424cf19785c9",
"https://deno.land/[email protected]/fs/walk.ts": "c1e6b43f72a46e89b630140308bd51a4795d416a416b4cfb7cd4bd1e25946723",
"https://deno.land/[email protected]/path/_common/assert_path.ts": "061e4d093d4ba5aebceb2c4da3318bfe3289e868570e9d3a8e327d91c2958946",
"https://deno.land/[email protected]/path/_common/basename.ts": "0d978ff818f339cd3b1d09dc914881f4d15617432ae519c1b8fdc09ff8d3789a",
@@ -1554,6 +1551,7 @@
"https://deno.land/[email protected]/path/extname.ts": "2da4e2490f3b48b7121d19fb4c91681a5e11bd6bd99df4f6f47d7a71bb6ecdf2",
"https://deno.land/[email protected]/path/format.ts": "3457530cc85d1b4bab175f9ae73998b34fd456c830d01883169af0681b8894fb",
"https://deno.land/[email protected]/path/from_file_url.ts": "e7fa233ea1dff9641e8d566153a24d95010110185a6f418dd2e32320926043f8",
"https://deno.land/[email protected]/path/glob.ts": "b8333cbb4aaaeb54ca6d6c43e0b69fb13c9481c69ed7a3c64a3d0d9daf2af769",
"https://deno.land/[email protected]/path/glob_to_regexp.ts": "74d7448c471e293d03f05ccb968df4365fed6aaa508506b6325a8efdc01d8271",
"https://deno.land/[email protected]/path/is_absolute.ts": "67232b41b860571c5b7537f4954c88d86ae2ba45e883ee37d3dec27b74909d13",
"https://deno.land/[email protected]/path/is_glob.ts": "567dce5c6656bdedfc6b3ee6c0833e1e4db2b8dff6e62148e94a917f289c06ad",
+1 -1
View File
@@ -44,7 +44,7 @@ for await (const entry of stylesheets) {
);
// advanced linting with stylelint
lint(entry, content, flags.fix);
await lint(entry, content, flags.fix);
}
// if any files are missing, cause the workflow to fail
+10 -174
View File
@@ -1,187 +1,23 @@
import { deepMerge } from "std/collections/deep_merge.ts";
import * as color from "std/fmt/colors.ts";
import { WalkEntry } from "std/fs/mod.ts";
import { relative } from "std/path/mod.ts";
import "npm:postcss-less";
import stylelint from "npm:stylelint";
import stylelintConfigStandard from "npm:stylelint-config-standard";
import stylelintConfigRecommended from "npm:stylelint-config-recommended";
import postcssLess from "npm:postcss-less";
import "npm:stylelint-config-standard";
import "npm:stylelint-config-recommended";
import { log } from "@/lint/logger.ts";
import { relative } from "https://deno.land/[email protected]/path/mod.ts";
import { REPO_ROOT } from "@/deps.ts";
import { WalkEntry } from "std/fs/walk.ts";
import { log } from "@/lint/logger.ts";
const config: stylelint.Config = {
customSyntax: postcssLess,
rules: {
"selector-class-pattern": null,
"custom-property-pattern": null,
"selector-id-pattern": null,
"rule-empty-line-before": null,
"comment-empty-line-before": null,
"custom-property-empty-line-before": null,
"at-rule-empty-line-before": null,
"declaration-empty-line-before": null,
"property-no-vendor-prefix": null,
"alpha-value-notation": null,
"color-function-notation": null,
"hue-degree-notation": null,
// less doesn't care about these
"no-invalid-position-at-import-rule": null,
"no-invalid-double-slash-comments": null,
"at-rule-disallowed-list": [[
"/^font.*/",
], {
message: (atRule: string) =>
`At-rule ${atRule} is not allowed in Catppuccin userstyles`,
}],
"property-disallowed-list": [[
// disallow setting fonts
"/font.*/",
// ideally we could disallow these, but CSS continues to be gross
// "/animation.*/",
// "/transition.*/",
// prefer `border-color` over `border`, `outline-color` over `outline`, etc.
"border",
"outline",
], {
message: (prop: string) => {
if (["border", "outline"].includes(prop)) {
return `Use \`${prop}-color\` instead of \`${prop}\``;
} else {
return `Property \`${prop}\` is not allowed in Catppuccin userstyles`;
}
},
}],
"function-no-unknown": [
true,
{
ignoreFunctions: [
// generated from https://lesscss.org/functions/
// via `Array.from(document.querySelectorAll('.section-content h3.docs-heading'), heading => heading.textContent.replace('\n', ''))`
"%",
"abs",
"acos",
"alpha",
"argb",
"asin",
"atan",
"average",
"blue",
"boolean",
"ceil",
"color",
"contrast",
"convert",
"cos",
"darken",
"data-uri",
"default",
"desaturate",
"difference",
"e",
"each",
"escape",
"exclusion",
"extract",
"fade",
"fadein",
"fadeout",
"floor",
"get-unit",
"green",
"greyscale",
"hardlight",
"hsl",
"hsla",
"hsv",
"hsva",
"hsvhue",
"hsvsaturation",
"hsvvalue",
"hue",
"if",
"image-height",
"image-size",
"image-width",
"iscolor",
"isdefined",
"isem",
"iskeyword",
"isnumber",
"ispercentage",
"ispixel",
"isruleset",
"isstring",
"isunit",
"isurl",
"length",
"lighten",
"lightness",
"luma",
"luminance",
"max",
"min",
"mix",
"mod",
"multiply",
"negation",
"overlay",
"percentage",
"pi",
"pow",
"range",
"red",
"replace",
"rgb",
"rgba",
"round",
"saturate",
"saturation",
"screen",
"shade",
"sin",
"softlight",
"spin",
"sqrt",
"svg-gradient",
"tan",
"tint",
"unit",
],
},
],
"function-name-case": null,
"no-descending-specificity": null,
"media-feature-range-notation": "prefix",
},
};
const base = deepMerge(
stylelintConfigRecommended,
{ ...stylelintConfigStandard, extends: {} },
);
export const lint = (entry: WalkEntry, content: string, fix: boolean) => {
export const lint = async (entry: WalkEntry, content: string, fix: boolean) => {
const file = relative(REPO_ROOT, entry.path);
stylelint.lint({
config: deepMerge(base, config),
files: entry.path,
fix,
})
await stylelint.lint({ files: entry.path, fix })
.then(({ results }) => {
results.map((result) => {
result.warnings.map((warning) => {
// some cleanup for fancier logging, dims the rule name
// Some cleanup for fancier logging, dims the rule name
const message = warning.text?.replace(
new RegExp(`\\(?${warning.rule}\\)?`),
color.dim(`(${warning.rule})`),