-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
general/development/policies/deprecation/scss-deprecation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
title: SCSS Deprecation | ||
tags: | ||
- Processes | ||
- Core development | ||
- Deprecation | ||
- SCSS | ||
--- | ||
|
||
## When should SCSS be deprecated? | ||
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. | ||
|
||
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. | ||
|
||
:::tip | ||
|
||
If all the styles depending on the same parent are deprecated, is strongly recommended to deprecate the parent selector. | ||
|
||
::: | ||
|
||
## How it works | ||
|
||
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. | ||
|
||
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. | ||
|
||
## How to deprecate SCSS code | ||
|
||
To deprecate SCSS code, follow these steps: | ||
|
||
1. Remove the SCSS code that is no longer in use from the original file. | ||
2. Add the removed SCSS code to the `deprecated.scss` file. | ||
3. Add the `deprecated-styles` mixin to the removed SCSS code. | ||
4. Add a comment to the removed SCSS code explaining why it has been deprecated. | ||
|
||
**Example 1: SCSS code is no longer in use** | ||
|
||
```scss title="theme/boost/scss/moodle/deprecated.scss" | ||
// The following styles are deprecated because they are no longer in use. | ||
// Deprecating the parent selector that contains all the deprecated styles. | ||
.path-course-view li.activity .foo { | ||
@include deprecated-styles(); | ||
} | ||
.path-course-view li.activity .foo > a { | ||
text-decoration: none; | ||
color: $secondary; | ||
} | ||
.path-course-view li.activity .foo > a:hover { | ||
color: $primary; | ||
} | ||
``` | ||
|
||
**Example 2: Helper class has been renamed** | ||
|
||
```scss title="theme/boost/scss/moodle/deprecated.scss" | ||
// The class ".foo" is deprecated. Use ".bar" instead. | ||
.foo { | ||
@include deprecated-styles(); | ||
|
||
color: $pink; | ||
@include border-right-radius(0); | ||
border: $border-width solid $border-color; | ||
table { | ||
margin: 1rem; | ||
} | ||
table > tbody { | ||
padding: .5rem; | ||
} | ||
} | ||
``` | ||
|
||
## Check deprecated styles in Behat tests | ||
|
||
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. | ||
|
||
```bash | ||
php admin/tool/behat/cli/init.php --scss-deprecations | ||
``` | ||
|
||
Then, when running Behat tests, the following message will be displayed: | ||
|
||
```bash | ||
Run optional tests: | ||
... | ||
- SCSS deprecations: Yes | ||
``` | ||
|
||
If deprecated styles are being used, the test will fail with the following message: | ||
|
||
```bash | ||
Deprecated style in use (Exception) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters