Skip to content

Commit a256a03

Browse files
committed
[docs] Add SCSS deprecation page
1 parent 7a2f506 commit a256a03

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

general/development/policies/deprecation/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,6 @@ Named parameter arguments are available from PHP 8.0 onwards.
232232
- [String deprecation](../../../projects/api/string-deprecation.md)
233233
- [External functions deprecation](/docs/apis/subsystems/external/writing-a-service#deprecation)
234234
- [Capabilities deprecation](/docs/apis/subsystems/access#deprecating-a-capability)
235+
- [SCSS deprecation](./scss-deprecation.md)
235236
- [Process](../../process.md)
236237
- [Release process](../../process/release/index.md)
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: SCSS Deprecation
3+
tags:
4+
- Processes
5+
- Core development
6+
- Deprecation
7+
- SCSS
8+
---
9+
import { Since } from '@site/src/components';
10+
11+
<Since versions={["4.4"]} issueNumber={"MDL-78334"} />
12+
13+
Since Moodle 4.4, it's possible to deprecate SCSS styles and classes. This allows us to safely remove SCSS and will help us keep the code cleaner and more organized.
14+
15+
The most common scenarios where this functionality can be used is when specific SCSS code is not being used anywhere, when the name of a class is changed or a class should not be used in the future.
16+
17+
:::info When should SCSS be removed?
18+
19+
There are situations where deprecation does not make sense. For example when a whole functionality is being removed, or a very specific SCSS class is no longer used by the code. If it is very unlikely that the SCSS class is used by any other code, it can simply be removed without the full deprecation process.
20+
21+
:::
22+
23+
## How it works
24+
25+
A new SCSS file called `deprecated.scss` has been added to the `theme/boost/scss/moodle` folder. All the deprecated SCSS code should be added to this file.
26+
27+
In this file a new mixin called `deprecated-styles` has been also added. This mixin will add a red backgound to the deprecated styles and also a `:before` pseudo-element with the text "Deprecated style in use". It is important to note that `deprecated-styles` mixin will only affect sites with `themedesignermode` setting enabled or behat test running sites.
28+
29+
:::tip
30+
31+
If all the styles depending on the same parent are deprecated, is strongly recommended to deprecate the parent selector.
32+
33+
:::
34+
35+
## How to deprecate SCSS code
36+
37+
To deprecate SCSS code, follow these steps:
38+
39+
1. Remove the SCSS code that is no longer in use from the original file.
40+
2. Add the removed SCSS code to the `deprecated.scss` file under the comment for the current version `// Deprecated since Moodle X.Y.`
41+
3. Add the `deprecated-styles` mixin to the removed SCSS code.
42+
4. Add a comment to the removed SCSS code explaining why it has been deprecated.
43+
44+
:::note
45+
46+
If there is no section for the current version in the `deprecated.scss` file, it should be added. See [Final deprecation](#final-deprecation).
47+
48+
:::
49+
50+
**Example 1: Helper class has been removed**
51+
52+
```scss title="theme/boost/scss/moodle/deprecated.scss"
53+
// The class ".foo" is deprecated. Use ".bar" instead.
54+
.foo {
55+
@include deprecated-styles();
56+
57+
color: $pink;
58+
@include border-right-radius(0);
59+
border: $border-width solid $border-color;
60+
table {
61+
margin: 1rem;
62+
}
63+
table > tbody {
64+
padding: .5rem;
65+
}
66+
}
67+
```
68+
69+
**Example 2: SCSS code is no longer in use**
70+
71+
```scss title="theme/boost/scss/moodle/deprecated.scss"
72+
// The following styles are deprecated because they are no longer in use.
73+
// Deprecating the parent selector that contains all the deprecated styles.
74+
.path-course-view li.activity .foo {
75+
@include deprecated-styles();
76+
}
77+
.path-course-view li.activity .foo > a {
78+
text-decoration: none;
79+
color: $secondary;
80+
}
81+
.path-course-view li.activity .foo > a:hover {
82+
color: $primary;
83+
}
84+
```
85+
86+
## Final deprecation
87+
88+
When adding SCSS code to the `deprecated.scss` file, it is important to add it under the comment with the version when the code was deprecated. If that comment still doesn't exist, it should be added:
89+
90+
```scss title="theme/boost/scss/moodle/deprecated.scss"
91+
//
92+
// Deprecated since Moodle X.Y.
93+
//
94+
```
95+
96+
And alongside with that, a new issue should be created in the tracker to remove the deprecated SCSS code with the title `Remove strings deprecated in X.Y` and in the epic `X.[Y+4]` deprecations.
97+
98+
After 4 major versions, the deprecated SCSS code will be removed from the `deprecated.scss` file.
99+
100+
## Check deprecated styles in Behat tests
101+
102+
Is is possible to check if deprecated styles are being used while running Behat tests. To do so, add the `--scss-deprecations` flag to the Behat init command.
103+
104+
```bash
105+
php admin/tool/behat/cli/init.php --scss-deprecations
106+
```
107+
108+
Then, when running Behat tests, the following message will be displayed:
109+
110+
```bash
111+
Run optional tests:
112+
[...]
113+
- SCSS deprecations: Yes
114+
```
115+
116+
If deprecated styles are being used, the test will fail with the following message:
117+
118+
```bash
119+
Deprecated style in use (Exception)
120+
```

0 commit comments

Comments
 (0)