Skip to content

Commit b3dc749

Browse files
authored
feat(lint): add prettier formatter to assert LESS files whitespaces
Compared to Stylelint, Prettier is very simple tool and I am quite supprised Stylelint is deprecating the whitespace rules in favor of Prettier. For LESS it seems ok, for JS, we should never enable Prettier as formatting is part of a code and improves readability. As Prettier is an opinionated formatter instead of an linter, we need to satisfy it everywhere without exceptions. When I was crafting this PR, I found several Prettier issues and proposed changes to Prettier: Fix semicolon duplicated at the end of LESS file prettier/prettier#14007 Fix no space after unary minus when followed by opening parenthesis in LESS prettier/prettier#14008 Do not change case of property name if inside a variable declaration in LESS prettier/prettier#14034 In this PR, these changes are contained and Prettier is patched before it is run. Once the changes are merged in prettier and stable release is made, they can be removed. This PR fixes minor whitespaces unfixed/undetected in GH-2610. And also asserts: PHP port of the LESS fails to compile colors.less #1832 feat(lint): add stylelint overrides and variation files #2593 (comment) Prettier has no built in support to dump the diff - prettier/prettier#6885 - so we dump it in the CI using git.
1 parent 5b012ba commit b3dc749

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+235
-384
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ jobs:
1414
run: yarn && yarn add -D eslint-config-airbnb-base eslint-plugin-unicorn eslint-plugin-jest@^26.9.0 @typescript-eslint/eslint-plugin @typescript-eslint/parser typescript
1515
- name: Lint JS and LESS files
1616
run: npm run lint
17+
- name: Assert LESS files formatting using Prettier
18+
run: >
19+
yarn add -D github:fomantic/prettier#2.8.1-patched
20+
&& npx prettier --loglevel warn '!dist' '!test/coverage' '!src/semantic.less' '**/*.{css,less,overrides,variables}' --write
21+
&& git restore package.json yarn.lock
22+
&& git add . -N && git diff --exit-code
1723
test:
1824
name: Test build process on node ${{ matrix.node-version }}
1925
runs-on: ubuntu-latest

.prettierrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
tabWidth: 4,
3+
overrides: [
4+
{
5+
files: ['*.less', '*.overrides', '*.variables'],
6+
options: {
7+
parser: 'less',
8+
printWidth: Infinity,
9+
},
10+
},
11+
],
12+
};

.stylelintrc.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ module.exports = {
1111
'at-rule-empty-line-before': null,
1212
'at-rule-name-case': null,
1313
'at-rule-no-unknown': null,
14-
'block-closing-brace-newline-before': null, // fix bad formatting with "each()"
1514
'color-function-notation': 'legacy',
1615
'color-hex-case': 'lower',
17-
'declaration-block-trailing-semicolon': null, // fix bad formatting with "each()"
16+
'declaration-colon-newline-after': null, // handled by Prettier
1817
'function-no-unknown': null,
19-
indentation: null, // TODO change to "4" once https://github.com/fomantic/Fomantic-UI/pull/2593#discussion_r1045131096 is fixed
18+
'import-notation': null,
19+
indentation: null, // handled by Prettier
2020
linebreaks: 'unix',
2121
'max-line-length': null,
2222
'no-descending-specificity': null,
23-
'no-extra-semicolons': null, // fix GH-1832 - workaround for wikimedia/less.php parser
23+
'no-extra-semicolons': null, // handled by Prettier
2424
'no-duplicate-selectors': null,
2525
'number-max-precision': 5,
2626
'property-case': null,
@@ -38,10 +38,9 @@ module.exports = {
3838

3939
// TODO rules to be removed/fixed in v2.10.0 as fixes are not compatible with IE11
4040
'alpha-value-notation': 'number', // https://caniuse.com/mdn-css_properties_opacity_percentages
41+
'selector-not-notation': null, // https://caniuse.com/css-not-sel-list
4142

4243
// TODO
43-
'selector-not-notation': null, // 169 errors
44-
'import-notation': null, // 56 errors
4544
'keyframes-name-pattern': null, // 50 errors
4645
'block-no-empty': null, // 25 errors
4746
'selector-no-vendor-prefix': null, // 19 errors

src/definitions/elements/button.less

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@
256256
/* Vertical */
257257
.ui.vertical.animated.button .visible.content,
258258
.ui.vertical.animated.button .hidden.content {
259-
transition: top @animationDuration @animationEasing, transform @animationDuration @animationEasing;
259+
transition:
260+
top @animationDuration @animationEasing,
261+
transform @animationDuration @animationEasing;
260262
}
261263
.ui.vertical.animated.button .visible.content {
262264
transform: translateY(0);
@@ -282,7 +284,9 @@
282284
/* Fade */
283285
.ui.fade.animated.button .visible.content,
284286
.ui.fade.animated.button .hidden.content {
285-
transition: opacity @animationDuration @animationEasing, transform @animationDuration @animationEasing;
287+
transition:
288+
opacity @animationDuration @animationEasing,
289+
transform @animationDuration @animationEasing;
286290
}
287291
.ui.fade.animated.button .visible.content {
288292
left: auto;
@@ -897,6 +901,7 @@
897901
.ui.tertiary.button {
898902
transition: color @defaultDuration @defaultEasing !important;
899903
border-radius: 0;
904+
// prettier-ignore
900905
margin:
901906
(@verticalPadding - @tertiaryVerticalPadding)
902907
(@horizontalMargin)

src/definitions/elements/icon.less

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,7 @@ i.icons {
443443
}
444444
}
445445

446-
& when ((@variationIconGroups) or (@variationIconCorner))
447-
and ((@variationIconBordered) or (@variationIconCircular)) {
446+
& when ((@variationIconGroups) or (@variationIconCorner)) and ((@variationIconBordered) or (@variationIconCircular)) {
448447
/*************************************************
449448
Bordered/circular with corner or group icons
450449
*************************************************/
@@ -527,7 +526,7 @@ and ((@variationIconBordered) or (@variationIconCircular)) {
527526
}
528527
}
529528
});
530-
};
529+
}
531530

532531
& when (@variationIconDeprecated) {
533532
/* Deprecated *In/Out Naming Conflict) */

src/definitions/modules/rating.less

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@
107107
0 -@shadowWidth 0 @c,
108108
-@shadowWidth 0 0 @c,
109109
0 @shadowWidth 0 @c,
110-
@shadowWidth 0 0 @c
111-
;
110+
@shadowWidth 0 0 @c;
112111
}
113112
.ui.@{color}.rating .icon.selected,
114113
.ui.@{color}.rating .icon.selected.active,
@@ -119,8 +118,7 @@
119118
0 -@shadowWidth 0 @h,
120119
-@shadowWidth 0 0 @h,
121120
0 @shadowWidth 0 @h,
122-
@shadowWidth 0 0 @h
123-
;
121+
@shadowWidth 0 0 @h;
124122

125123
-webkit-text-stroke: unset;
126124
background-clip: unset;

src/definitions/modules/toast.less

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,9 @@
589589
}
590590

591591
.ui.hoverfloating.message:hover when (@variationToastMessage) and (@variationToastFloating) {
592-
box-shadow: 0 0 0 1px inset, @floatingShadow;
592+
box-shadow:
593+
0 0 0 1px inset,
594+
@floatingShadow;
593595
}
594596

595597
.ui.center.toast-container .toast-box,

src/definitions/views/card.less

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,7 @@
675675
box-shadow:
676676
@borderShadow,
677677
0 @coloredShadowDistance 0 0 @c,
678-
@shadowBoxShadow
679-
;
678+
@shadowBoxShadow;
680679
}
681680
& when (@variationCardLink) {
682681
.ui.cards a.@{color}.card:hover,
@@ -688,8 +687,7 @@
688687
box-shadow:
689688
@borderShadow,
690689
0 @coloredShadowDistance 0 0 @h,
691-
@shadowHoverBoxShadow
692-
;
690+
@shadowHoverBoxShadow;
693691
}
694692
}
695693
& when (@variationCardBasic) {
@@ -727,8 +725,7 @@
727725
box-shadow:
728726
0 @shadowDistance 3px 0 @solidWhiteBorderColor,
729727
0 @coloredShadowDistance 0 0 @l,
730-
0 0 0 @borderWidth @solidWhiteBorderColor
731-
;
728+
0 0 0 @borderWidth @solidWhiteBorderColor;
732729
}
733730
& when (@variationCardLink) {
734731
.ui.inverted.cards a.@{color}.card:hover,
@@ -740,8 +737,7 @@
740737
box-shadow:
741738
0 @shadowDistance 3px 0 @solidWhiteBorderColor,
742739
0 @coloredShadowDistance 0 0 @lh,
743-
0 0 0 @borderWidth @solidWhiteBorderColor
744-
;
740+
0 0 0 @borderWidth @solidWhiteBorderColor;
745741
}
746742
}
747743
& when (@variationCardBasic) {

src/themes/amazon/elements/button.variables

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
opacity @defaultDuration @defaultEasing,
1212
background-color @defaultDuration @defaultEasing,
1313
color @defaultDuration @defaultEasing,
14-
background @defaultDuration @defaultEasing
15-
;
14+
background @defaultDuration @defaultEasing;
1615

1716
@hoverBackgroundColor: #e0e0e0;
1817

@@ -24,18 +23,14 @@
2423
@backgroundImage: linear-gradient(rgba(255, 255, 255, 0), rgba(0, 0, 0, 0.1));
2524
@boxShadow:
2625
0 1px 0 1px rgba(255, 255, 255, 0.3) inset,
27-
0 0 0 1px #adb2bb inset
28-
;
26+
0 0 0 1px #adb2bb inset;
2927

3028
@coloredBackgroundImage: linear-gradient(rgba(255, 255, 255, 0.2), rgba(0, 0, 0, 0.2));
31-
@coloredBoxShadow:
32-
0 1px 0 0 rgba(255, 255, 255, 0.2) inset
33-
;
29+
@coloredBoxShadow: 0 1px 0 0 rgba(255, 255, 255, 0.2) inset;
3430

3531
@downBoxShadow:
3632
0 0 0 1px #adb2bb inset,
37-
0 1px 3px rgba(0, 0, 0, 0.2) inset
38-
;
33+
0 1px 3px rgba(0, 0, 0, 0.2) inset;
3934

4035
@labeledIconBackgroundColor: #313a43;
4136
@labeledIconColor: #fff;

src/themes/bootstrap3/elements/button.variables

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,20 @@
3838
@basicHoverBackground: transparent;
3939
@basicDownBoxShadow:
4040
0 0 0 1px #adadad inset,
41-
0 3px 5px rgba(0, 0, 0, 0.125) inset
42-
;
41+
0 3px 5px rgba(0, 0, 0, 0.125) inset;
4342

4443
@groupButtonOffset: 0 0 0 -1px;
4544
@verticalGroupOffset: 0 0 -1px 0;
4645

4746
/* States */
4847

4948
@hoverBackgroundColor: #e6e6e6;
50-
@hoverBoxShadow:
51-
0 0 0 1px #adadad inset
52-
;
49+
@hoverBoxShadow: 0 0 0 1px #adadad inset;
5350

5451
@downBackgroundColor: #e6e6e6;
5552
@downBoxShadow:
5653
0 0 0 1px #adadad inset,
57-
0 3px 5px rgba(0, 0, 0, 0.125) inset
58-
;
54+
0 3px 5px rgba(0, 0, 0, 0.125) inset;
5955

6056
@activeBackgroundColor: #e6e6e6;
6157

0 commit comments

Comments
 (0)