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

[stylelint-polaris][v5] Final rule categorization #7828

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 56 additions & 36 deletions stylelint-polaris/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const {getCustomPropertyNames, tokens} = require('@shopify/polaris-tokens');
const {
getCustomPropertyNames,
createVar,
tokens,
} = require('@shopify/polaris-tokens');

/** @type {import('./plugins/coverage').PrimaryOptions} */
const stylelintPolarisCoverageOptions = {
Expand Down Expand Up @@ -27,14 +31,15 @@ const stylelintPolarisCoverageOptions = {
],
'stylelint-polaris/at-rule-disallowed-list': {
include: [
// mixins
// Legacy mixins
/([\w-]+\.)?color-icon($|\()/,
/([\w-]+\.)?recolor-icon($|\()/,
/([\w-]+\.)?control-backdrop($|\()/,
/([\w-]+\.)?ms-high-contrast-color/,
],
},
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$polaris-colors/,
/\$color-filter-palette-data/,
/\$color-palette-data/,
Expand All @@ -55,12 +60,12 @@ const stylelintPolarisCoverageOptions = {
'/^animation/': ['ms', 's'],
'/^transition/': ['ms', 's'],
},
{severity: 'warning'},
],
'stylelint-polaris/at-rule-disallowed-list': {
include: [/([\w-]+\.)?skeleton-shimmer($|\()/],
},
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$duration-data/,
/\$polaris-duration-map/,
/\$skeleton-shimmer-duration/,
Expand All @@ -80,7 +85,6 @@ const stylelintPolarisCoverageOptions = {
'/^font/': ['px', 'rem', 'em'],
'line-height': ['px', 'rem', 'em'],
},
{severity: 'warning'},
],
'function-disallowed-list': [
/([\w-]+\.)?font-family/,
Expand Down Expand Up @@ -108,6 +112,7 @@ const stylelintPolarisCoverageOptions = {
],
},
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$typography-condensed/,
/\$typography-condensed/,
/\$base-font-size/,
Expand All @@ -123,24 +128,15 @@ const stylelintPolarisCoverageOptions = {
layout: {
'declaration-property-value-disallowed-list': [
{
display: ['grid', 'flex'],
top: [/(?!var\(--p-).+$/],
bottom: [/(?!var\(--p-).+$/],
left: [/(?!var\(--p-).+$/],
right: [/(?!var\(--p-).+$/],
width: [/(?!var\(--p-).+$/],
height: [/(?!var\(--p-).+$/],
'z-index': [/(?!var\(--p-).+$/],
'/^width/': [/(?!var\(--p-).+$/],
'/^height/': [/(?!var\(--p-).+$/],
},
{severity: 'warning'},
],
'declaration-property-unit-disallowed-list': [
{
'/^width/': ['px', 'rem', 'em'],
'/^height/': ['px', 'rem', 'em'],
},
{severity: 'error'},
],
'property-disallowed-list': [
[
'position',
Expand Down Expand Up @@ -182,11 +178,13 @@ const stylelintPolarisCoverageOptions = {
/([\w-]+\.)?hidden-when-printing($|\()/,
/([\w-]+\.)?print-hidden($|\()/,
/([\w-]+\.)?layout-flex-fix($|\()/,
/([\w-]+\.)?safe-area-for($|\()/,
/([\w-]+\.)?skeleton-page-header-layout($|\()/,
/([\w-]+\.)?skeleton-page-secondary-actions-layout($|\()/,
],
},
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$layout-width-data/,
/\$navigation-width/,
/\$small-thumbnail-size/,
Expand Down Expand Up @@ -216,9 +214,9 @@ const stylelintPolarisCoverageOptions = {
'/^margin/': ['px', 'rem', 'em'],
'/^gap/': ['px', 'rem', 'em'],
},
{severity: 'warning'},
],
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$polaris-spacing/,
/\$spacing-data/,
/\$actions-vertical-spacing/,
Expand All @@ -237,7 +235,6 @@ const stylelintPolarisCoverageOptions = {
'outline-offset': ['px', 'rem', 'em'],
outline: ['px', 'rem', 'em'],
},
{severity: 'warning'},
],
'stylelint-polaris/at-rule-disallowed-list': {
include: [
Expand All @@ -252,6 +249,7 @@ const stylelintPolarisCoverageOptions = {
],
},
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$border-radius-data/,
/\$border-width-data/,
/\$borders-data/,
Expand All @@ -276,10 +274,10 @@ const stylelintPolarisCoverageOptions = {
{
'box-shadow': ['px', 'rem', 'em'],
},
{severity: 'warning'},
],
'property-disallowed-list': [['text-shadow'], {severity: 'warning'}],
'property-disallowed-list': ['text-shadow'],
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$shadows-data/,
/\$fixed-element-stacking-order/,
/\$global-elements/,
Expand All @@ -293,6 +291,21 @@ const stylelintPolarisCoverageOptions = {
/--p-top-bar-shadow/,
],
},
'z-index': {
'declaration-property-value-allowed-list': [
{
'z-index': Object.keys(tokens.zIndex).map(createVar),
},
],
'function-disallowed-list': [/([\w-]+\.)?z-index/],
'stylelint-polaris/global-disallowed-list': [
// Legacy mixin map-get data
/\$fixed-element-stacking-order/,
/\$global-elements/,
// Legacy custom properties
/--p-override-loading-z-index/,
],
},
conventions: {
'stylelint-polaris/custom-properties-allowed-list': {
// Allow any custom property not prefixed with `--p-`, `--pc-`, or `--polaris-version-`
Expand All @@ -309,30 +322,26 @@ const stylelintPolarisCoverageOptions = {
],
},
},
'stylelint-polaris/global-disallowed-list': [
/ \* \$/,
// Legacy custom properties
/--p-override-none/,
/--p-override-one/,
/--p-override-zero/,
/--p-non-null-content/,
],
'stylelint-polaris/media-queries-allowed-list': {
// Allowed media types and media conditions
// https://www.w3.org/TR/mediaqueries-5/#media
allowedMediaTypes: ['print', 'screen'],
allowedMediaFeatureNames: ['forced-colors', '-ms-high-contrast'],
},
},
mediaQueries: {
breakpoints: {
Copy link
Member

@aaronccasanova aaronccasanova Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mediaQueries may be more appropriate as this category can lint more than Polaris breakpoints e.g. media types, media features, media conditions/operators, etc. Thoughts?

Copy link
Member Author

@chloerice chloerice Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aaronccasanova What do you think about re-categorizing the non-breakpoint related options in the breakpoints category media-query-allowed-list over to conventions? It seems like that would be a better fit so the coverage site can map the results related to breakpoints to the breakpoints token coverage.

// Legacy functions
'function-disallowed-list': [
/([\w-]+\.)?breakpoint/,
/([\w-]+\.)?layout-width/,
],
'stylelint-polaris/media-queries-allowed-list': {
// Allowed media types and media conditions
// https://www.w3.org/TR/mediaqueries-5/#media
allowedMediaTypes: ['print', 'screen'],
allowedMediaFeatureNames: ['forced-colors', '-ms-high-contrast'],
allowedScssInterpolations: [
// TODO: Add utility to @shopify/polaris-tokens to getMediaConditionNames
/^\$p-breakpoints-(xs|sm|md|lg|xl)-(up|down|only)$/,
],
},
// Legacy mixins
'stylelint-polaris/at-rule-disallowed-list': {
include: [
/([\w-]+\.)?after-topbar-sheet($|\()/,
Expand Down Expand Up @@ -367,7 +376,8 @@ const stylelintPolarisCoverageOptions = {
],
},
},
legacySass: {
legacy: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// Legacy mixins
'stylelint-polaris/at-rule-disallowed-list': {
include: [
/([\w-]+\.)?base-button-disabled($|\()/,
Expand All @@ -376,6 +386,8 @@ const stylelintPolarisCoverageOptions = {
/([\w-]+\.)?button-full-width($|\()/,
/([\w-]+\.)?button-outline-disabled($|\()/,
/([\w-]+\.)?button-outline($|\()/,
/([\w-]+\.)?control-backdrop($|\()/,
/([\w-]+\.)?list-selected-indicator($|\()/,
/([\w-]+\.)?plain-button-backdrop($|\()/,
/([\w-]+\.)?unstyled-button($|\()/,
/([\w-]+\.)?skeleton-content($|\()/,
Expand All @@ -384,15 +396,23 @@ const stylelintPolarisCoverageOptions = {
/([\w-]+\.)?unstyled-list($|\()/,
/([\w-]+\.)?range-thumb-selectors($|\()/,
/([\w-]+\.)?range-track-selectors($|\()/,
/([\w-]+\.)?state($|\()/,
/([\w-]+\.)?visually-hidden($|\()/,
],
},
// Legacy functions
'function-disallowed-list': [
/([\w-]+\.)?available-names/,
/([\w-]+\.)?map-extend/,
/([\w-]+\.)?control-backdrop($|\()/,
/([\w-]+\.)?list-selected-indicator($|\()/,
/([\w-]+\.)?state($|\()/,
],
'stylelint-polaris/global-disallowed-list': [
// Legacy variables
/ \* \$/,
// Legacy custom properties
/--p-override-none/,
/--p-override-one/,
/--p-override-zero/,
/--p-non-null-content/,
],
},
};
Expand Down