Skip to content

Commit

Permalink
Merge pull request #864 from Webperf-se/stylelint-update
Browse files Browse the repository at this point in the history
Stylelint - Add autodetect on new stylelint releases
  • Loading branch information
7h3Rabbit authored Jan 18, 2025
2 parents 5fa82cf + f00365d commit c6eb8d2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/update-software.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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=",
Expand Down
42 changes: 42 additions & 0 deletions helpers/update_stylelint_helper.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c6eb8d2

Please sign in to comment.