From f87a55423945943574c2e9d37628eb1cd2dd59b1 Mon Sep 17 00:00:00 2001 From: 7h3Rabbit <62792609+7h3Rabbit@users.noreply.github.com> Date: Sat, 18 Jan 2025 21:56:10 +0100 Subject: [PATCH] Update stylelint standard rules --- .github/workflows/update-software.yml | 4 +++ default.py | 7 +++++ helpers/update_stylelint_helper.py | 42 +++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 helpers/update_stylelint_helper.py diff --git a/.github/workflows/update-software.yml b/.github/workflows/update-software.yml index 1172f1aa..d94dd102 100644 --- a/.github/workflows/update-software.yml +++ b/.github/workflows/update-software.yml @@ -59,6 +59,8 @@ jobs: run: python default.py --update-definitions ${{ secrets.GITHUB_TOKEN }} - name: Update HTML and CSS references (MDN Web Docs) run: python default.py --update-mdn-sources + - name: Update Stylelint Standard Rules + run: python default.py --update-stylelint-rules - name: Update CREDITS.md run: python default.py --update-credits - name: Create pull request @@ -71,6 +73,7 @@ jobs: This pull request is used to make it easier to keep the software definitions up to date. Following files may be touched: + - defaults/css-stylelint-standard.json - defaults/software-sources.json - defaults/software-full.json - defaults/software-rules.json @@ -80,6 +83,7 @@ jobs: assignees: 7h3Rabbit reviewers: 7h3Rabbit add-paths: | + defaults/css-stylelint-standard.json defaults/software-sources.json defaults/software-full.json defaults/software-rules.json diff --git a/default.py b/default.py index 261f8d55..9554bc9e 100644 --- a/default.py +++ b/default.py @@ -29,6 +29,7 @@ from helpers.translation_helper import validate_translations from helpers.update_software_helper import filter_unknown_sources,\ update_licenses, update_software_info, update_user_agent +from helpers.update_stylelint_helper import update_stylelint_rules from tests.utils import clean_cache_files def show_test_help(global_translation): @@ -105,6 +106,10 @@ def update_credits(self, _): update_credits_markdown(self.language) sys.exit() + def update_stylelint(self, _): + update_stylelint_rules() + sys.exit(0) + def update_browser(self, _): update_user_agent() sys.exit(0) @@ -475,6 +480,7 @@ def handle_option(self, opt, arg): ("-c", "--credits", "--contributors"): self.show_credits, ("--uc", "--update-credits"): self.update_credits, ("-b", "--update-browser"): self.update_browser, + ("--usr", "--update-stylelint-rules"): self.update_stylelint, ("-d", "--update-definitions"): self.update_software_definitions, ("--ums", "--update-mdn-sources"): self.update_mdn, ("--ucr", "--update-carbon"): self.update_carbon_rating, @@ -530,6 +536,7 @@ def main(argv): "uc" ,"update-credits", "ums", "update-mdn-sources", "update-browser", "update-definitions=", + "usr", "update-stylelint-rules", "update-translations", "pr=", "prepare-release=", "cr=", "create-release=", diff --git a/helpers/update_stylelint_helper.py b/helpers/update_stylelint_helper.py new file mode 100644 index 00000000..5f602662 --- /dev/null +++ b/helpers/update_stylelint_helper.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +from datetime import timedelta +import json +import os +from pathlib import Path +from helpers.setting_helper import get_config + +USE_CACHE = get_config('general.cache.use') +CACHE_TIME_DELTA = timedelta(minutes=get_config('general.cache.max-age')) +CONFIG_WARNINGS = {} + +def update_stylelint_rules(): + print('updates rules used in defaults/css-stylelint-standard.json') + + base_directory = Path(os.path.dirname( + os.path.realpath(__file__)) + os.path.sep).parent + rules_path = os.path.join(base_directory, 'node_modules', 'stylelint', 'lib', 'rules') + rule_names = os.listdir(rules_path) + + rules = {} + for rule_name in rule_names: + if 'no-unknown' in rule_name: + rules[rule_name] = True + elif 'no-deprecated' in rule_name: + rules[rule_name] = True + elif 'no-invalid' in rule_name: + rules[rule_name] = True + elif 'no-vendor' in rule_name: + rules[rule_name] = True + elif 'no-empty' in rule_name: + rules[rule_name] = True + elif 'no-nonstandard' in rule_name: + rules[rule_name] = True + elif 'no-important' in rule_name: + rules[rule_name] = True + + stylelint_standard_path = os.path.join(base_directory, 'defaults', 'css-stylelint-standard.json') + with open(stylelint_standard_path, 'w', encoding='utf-8') as outfile: + json.dump({ + 'rules': rules + }, outfile, indent=4) +