Skip to content

Commit 8d0949c

Browse files
leagrdvalizedebray
andauthored
feat(eslint): automigration rules for bootstrap position helpers (#6335)
## 📄 Description - Added information in the migration guide of the removal of bootstrap position helpers - Added auto migration rules for the helper classes --------- Co-authored-by: Alizé Debray <[email protected]>
1 parent 9f7e069 commit 8d0949c

File tree

6 files changed

+90
-4
lines changed

6 files changed

+90
-4
lines changed

.changeset/slow-breads-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@swisspost/design-system-documentation': patch
3+
---
4+
5+
Added information in the migration guide regarding the removal of position helpers.

packages/documentation/src/stories/misc/migration-guide/migrationv9-10.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ export class MigrationV99Component extends LitElement {
192192
</li>
193193
<li class="mb-16">
194194
<p>
195+
<span data-info="automigration" class="tag tag-sm tag-info">🪄 migration rule</span>
195196
The gap classes naming (<code>gap-*</code>, <code>row-gap-*</code>,
196197
<code>column-gap-*</code>) has changed to pixel-based names
197-
<span class="tag tag-sm tag-danger">breaking</span> <span class="tag tag-sm tag-info">🪄 migration rule</span>
198198
</p>
199199
<ul>
200200
<li><code>*-1</code> is now <code>*-4</code></li>
@@ -210,7 +210,6 @@ export class MigrationV99Component extends LitElement {
210210
<ul>
211211
<li class="mb-16">
212212
<p>
213-
<span data-info="automigration" class="tag tag-sm tag-info">🪄 migration rule</span>
214213
Changed the percentage sizing utility classes (<code>w-*</code>,
215214
<code>h-*</code>, <code>mh-*</code>, <code>mw-*</code>) naming
216215
</p>
@@ -279,7 +278,6 @@ export class MigrationV99Component extends LitElement {
279278
We recommend using the <code>.elevation-*</code> classes instead.
280279
</p>
281280
</li>
282-
283281
<li class="mb-16">
284282
<p>
285283
<span data-info="automigration" class="tag tag-sm tag-info">🪄 migration rule</span>
@@ -367,6 +365,18 @@ export class MigrationV99Component extends LitElement {
367365
<li><code>.rounded-{top/bottom/start/end}</code> are now <code>.rounded-{top/bottom/start/end}-4</code></li>
368366
</ul>
369367
</li>
368+
<li class="mb-16">
369+
<p>
370+
<span data-info="automigration" class="tag tag-sm tag-info">🪄 migration rule</span>
371+
Removed some position helper classes that can be replaced with a combination of other utilities
372+
</p>
373+
<ul>
374+
<li><code>fixed-top</code> is now <code>position-fixed top-0 start-0 end-0 z-fixed</code></li>
375+
<li><code>fixed-bottom</code> is now <code>position-fixed bottom-0 start-0 end-0 z-fixed</code></li>
376+
<li><code>sticky-top</code> is now <code>position-sticky top-0 z-header</code></li>
377+
<li><code>sticky-bottom</code> is now <code>position-sticky bottom-0 z-header</code></li>
378+
</ul>
379+
</li>
370380
<li class="mb-16">
371381
<p>
372382
Removed all text color utility classes (<code>.text-*</code>)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# `no-deprecated-position-helpers`
2+
3+
Flags deprecated Bootstrap position helpers `fixed-[top/bottom]` and `sticky-[top/bottom]` classes and replace them with a combination of other utility classes.
4+
5+
- Type: problem
6+
- 🔧 Supports autofix (--fix)
7+
8+
## Rule Options
9+
10+
This rule does not have any configuration options.
11+
12+
## Example
13+
14+
### ❌ Invalid Code
15+
16+
```html
17+
<div class="fixed-top">Content</div>
18+
<div class="fixed-bottom">Content</div>
19+
<div class="sticky-top">Content</div>
20+
<div class="sticky-bottom">Content</div>
21+
```
22+
23+
### ✅ Valid Code
24+
25+
```html
26+
<div class="position-fixed top-0 start-0 end-0 z-fixed">Content</div>
27+
<div class="position-fixed bottom-0 start-0 end-0 z-fixed">Content</div>
28+
<div class="position-sticky top-0 z-header">Content</div>
29+
<div class="position-sticky bottom-0 z-header">Content</div>
30+
```

packages/eslint/src/rules/html/migrations/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ import noDeprecatedFontSizesRule, {
2929
import noDeprecatedChipFilter, {
3030
name as noDeprecatedChipFilterName,
3131
} from './no-deprecated-chip-filter';
32+
import noDeprecatedPositionHelpersRule, {
33+
name as noDeprecatedPositionHelpersRuleName,
34+
} from './no-deprecated-position-helpers';
3235

3336
import {
3437
rulePhase1 as noDeprecatedBreakpointsRulePhase1,
@@ -54,9 +57,10 @@ export const htmlMigrationRules = {
5457
[noFormTextRuleName]: noFormTextRule,
5558
[noDeprecatedFontWeightRuleName]: noDeprecatedFontWeightRule,
5659
[noDeprecatedShadowUtilitiesRuleName]: noDeprecatedShadowUtilitiesRule,
57-
[noDeprecatedElevationUtilitiesRuleName]: noDeprecatedElevationUtilitiesRule,
5860
[noDeprecatedHClearfixName]: noDeprecatedHClearfix,
5961
[noDeprecatedHVisuallyhiddenRuleName]: noDeprecatedHVisuallyhiddenRule,
62+
[noDeprecatedPositionHelpersRuleName]: noDeprecatedPositionHelpersRule,
63+
[noDeprecatedElevationUtilitiesRuleName]: noDeprecatedElevationUtilitiesRule,
6064
[noDeprecatedFontSizesRuleName]: noDeprecatedFontSizesRule,
6165
[noDeprecatedChipFilterName]: noDeprecatedChipFilter,
6266
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { createClassUpdateRule } from '../../../utils/create-class-update-rule';
2+
import { generateReplacedClassMessages } from '../../../utils/generate-messages';
3+
import { generateReplacedClassMutations } from '../../../utils/generate-mutations';
4+
5+
export const name = 'no-deprecated-position-helpers';
6+
7+
const classesMap = [
8+
{ old: 'fixed-top', new: 'position-fixed top-0 start-0 end-0 z-fixed' },
9+
{ old: 'fixed-bottom', new: 'position-fixed bottom-0 start-0 end-0 z-fixed' },
10+
{ old: 'sticky-top', new: 'position-sticky top-0 z-header' },
11+
{ old: 'sticky-bottom', new: 'position-sticky bottom-0 z-header' },
12+
];
13+
14+
export const data = generateReplacedClassMutations(classesMap);
15+
16+
export default createClassUpdateRule({
17+
name,
18+
type: 'problem',
19+
description:
20+
'Flags deprecated bootstrap position helpers "fixed-{top|bottom}" and "sticky-{top|bottom}" classes and replace them with a combination of other utility classes.',
21+
messages: generateReplacedClassMessages(classesMap),
22+
mutations: data,
23+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import rule, {
2+
name,
3+
data,
4+
} from '../../../../src/rules/html/migrations/no-deprecated-position-helpers';
5+
import { generatedDataTester } from '../../../utils/generated-data-tester';
6+
7+
const validData = [
8+
'position-fixed top-0 start-0 end-0 z-fixed',
9+
'position-fixed bottom-0 start-0 end-0 z-fixed',
10+
'position-sticky top-0 z-header',
11+
'position-sticky bottom-0 z-header',
12+
];
13+
14+
generatedDataTester(name, rule, data, validData);

0 commit comments

Comments
 (0)