forked from primer/css
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprecations.js
174 lines (169 loc) · 5.19 KB
/
deprecations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* This object's keys are (semver) version numbers, and the
* values are arrays of objects each with a "selectors"
* array and a "message" string.
*/
const versionDeprecations = {
'14.4.0': [
{
selectors: [
'.breadcrumb-item[aria-current]',
'.breadcrumb-item[aria-current]::after',
'.menu-item[aria-current]',
'.menu-item[aria-current]::before',
'.tabnav-tab[aria-current]',
'.filter-item[aria-current]',
'.SideNav-item[aria-current="page"]',
'.SideNav-item[aria-current="page"]::before',
'.SideNav-subItem[aria-current="page"]',
'.subnav-item[aria-current]',
'.UnderlineNav-item[aria-current]',
'.UnderlineNav-item[aria-current] .UnderlineNav-octicon',
'.pagination [aria-current]',
'.pagination [aria-current]:hover'
],
message: `These selectors are not needed anymore.`
}
],
'14.0.0': [
{
selectors: [
'.SelectMenu-item+.SelectMenu-item',
'.SelectMenu-divider:first-child',
'.SelectMenu-divider:last-child',
'.SelectMenu--hasFilter .SelectMenu-item:last-child',
'.SelectMenu-item[aria-checked="true"] .SelectMenu-icon'
],
message: `These selectors are deprecated and not used anymore.`
},
{
selectors: [
'.flex-item-equal',
'.flex-sm-item-equal',
'.flex-md-item-equal',
'.flex-lg-item-equal',
'.flex-xl-item-equal'
],
message: `This variable is deprecated. Use "flex-1" instead.`
},
{
selectors: ['.UnderlineNav-item.selected', '.UnderlineNav-item.selected .UnderlineNav-octicon'],
message: `Please use aria-selected="true" to indicate the selected state of an UnderlineNav item.`
},
{
variables: ['$status-pending'],
message: `This variable is deprecated.`
},
{
variables: ['$highlight-yellow'],
message: `This variable is deprecated.`
},
{
variables: ['$repo-private-text', '$repo-private-bg', '$repo-private-icon'],
message: `These variables are deprecated.`
},
{
variables: ['$marketingSpacers', '$allSpacers'],
message: `Please use the $marketing-spacers and $marketing-all-spacers variables.`
},
{
variables: ['$exploregrid-item-border-radius'],
message: `This variable is deprecated. Use "4px" instead.`
},
{
variables: ['$stats-switcher-py', '$stats-viewport-height'],
message: `These variables are deprecated.`
},
{
variables: ['$min_tab_size', '$max_tab_size'],
message: `These variables are deprecated.`
}
],
'13.0.0': [
{
selectors: [
'.btn-purple',
'.btn-purple:focus',
'.btn-purple.focus',
'.btn-purple:hover',
'.btn-purple.hover',
'.btn-purple:active',
'.btn-purple.selected',
'[open]>.btn-purple',
'.btn-purple:disabled',
'.btn-purple.disabled',
'.btn-purple .Counter'
],
message: `Please don't make purple buttons.`
},
{
selectors: ['.text-pending'],
message: `Please use the "text-yellow" class instead of "text-pending".`
},
{
selectors: ['.bg-pending'],
message: `Please use the "bg-yellow-dark" class instead of "bg-pending".`
},
{
selectors: [
'.container',
'.container::before',
'.container::after',
'.columns',
'.columns::before',
'.columns::after',
'.column',
'.one-third',
'.two-thirds',
'.one-fourth',
'.one-half',
'.three-fourths',
'.one-fifth',
'.four-fifths'
],
message: `Please use [grid classes](https://primer.style/css/objects/grid).`
},
{
selectors: ['.centered'],
message: `You can use the "mx-auto" class to center any element.`
},
{
selectors: [
'.dropdown-menu-content',
'.dropdown.active .dropdown-menu-content',
'.dropdown-menu-content.anim-scale-in'
],
message: `The "dropdown-menu-content" class is unnecessary.`
}
]
}
const {version: CURRENT_VERSION} = require('./package.json')
const semver = require('semver')
// map selectors to the version and message of their deprecation
const selectorDeprecations = new Map()
const variableDeprecations = new Map()
for (const [version, deps] of Object.entries(versionDeprecations)) {
for (const {selectors = [], variables = [], message} of deps) {
for (const selector of selectors) {
selectorDeprecations.set(selector, {version, message})
}
for (const variable of variables) {
variableDeprecations.set(variable, {version, message})
}
}
}
function isSelectorDeprecated(selector, version = CURRENT_VERSION) {
const deprecation = selectorDeprecations.get(selector)
return deprecation ? semver.gte(deprecation.version, version) : false
}
function isVariableDeprecated(variable, version = CURRENT_VERSION) {
const deprecation = variableDeprecations.get(variable)
return deprecation ? semver.gte(deprecation.version, version) : false
}
module.exports = {
versionDeprecations,
selectorDeprecations,
variableDeprecations,
isSelectorDeprecated,
isVariableDeprecated
}