2019-09-05 21:55:10 +03:00
|
|
|
/*
|
|
|
|
* 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 = {
|
2020-05-21 10:23:11 +03:00
|
|
|
'14.4.0': [
|
2020-01-23 08:37:41 +03:00
|
|
|
{
|
|
|
|
selectors: [
|
2020-05-21 10:23:11 +03:00
|
|
|
'.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'
|
2020-01-23 08:37:41 +03:00
|
|
|
],
|
|
|
|
message: `These selectors are not needed anymore.`
|
|
|
|
}
|
|
|
|
],
|
2019-11-01 01:48:16 +03:00
|
|
|
'14.0.0': [
|
2019-11-15 18:02:42 +03:00
|
|
|
{
|
|
|
|
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.`
|
|
|
|
},
|
2019-11-05 11:54:17 +03:00
|
|
|
{
|
2019-11-05 12:57:40 +03:00
|
|
|
selectors: [
|
|
|
|
'.flex-item-equal',
|
|
|
|
'.flex-sm-item-equal',
|
|
|
|
'.flex-md-item-equal',
|
|
|
|
'.flex-lg-item-equal',
|
|
|
|
'.flex-xl-item-equal'
|
|
|
|
],
|
2019-11-05 11:54:17 +03:00
|
|
|
message: `This variable is deprecated. Use "flex-1" instead.`
|
|
|
|
},
|
2019-11-01 02:20:15 +03:00
|
|
|
{
|
|
|
|
selectors: ['.UnderlineNav-item.selected', '.UnderlineNav-item.selected .UnderlineNav-octicon'],
|
|
|
|
message: `Please use aria-selected="true" to indicate the selected state of an UnderlineNav item.`
|
|
|
|
},
|
2019-11-01 01:48:16 +03:00
|
|
|
{
|
|
|
|
variables: ['$status-pending'],
|
|
|
|
message: `This variable is deprecated.`
|
|
|
|
},
|
2019-11-05 02:45:18 +03:00
|
|
|
{
|
|
|
|
variables: ['$highlight-yellow'],
|
|
|
|
message: `This variable is deprecated.`
|
|
|
|
},
|
2019-11-01 01:48:16 +03:00
|
|
|
{
|
|
|
|
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.`
|
|
|
|
}
|
|
|
|
],
|
2019-09-05 21:13:45 +03:00
|
|
|
'13.0.0': [
|
|
|
|
{
|
2019-09-10 23:44:25 +03:00
|
|
|
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'
|
|
|
|
],
|
2019-09-05 21:13:45 +03:00
|
|
|
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".`
|
|
|
|
},
|
|
|
|
{
|
2019-09-05 22:33:11 +03:00
|
|
|
selectors: [
|
2019-09-10 23:32:11 +03:00
|
|
|
'.container',
|
|
|
|
'.container::before',
|
|
|
|
'.container::after',
|
|
|
|
'.columns',
|
|
|
|
'.columns::before',
|
|
|
|
'.columns::after',
|
2019-09-05 22:33:11 +03:00
|
|
|
'.column',
|
|
|
|
'.one-third',
|
|
|
|
'.two-thirds',
|
|
|
|
'.one-fourth',
|
|
|
|
'.one-half',
|
|
|
|
'.three-fourths',
|
|
|
|
'.one-fifth',
|
|
|
|
'.four-fifths'
|
|
|
|
],
|
2019-09-05 21:13:45 +03:00
|
|
|
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.`
|
2019-09-11 00:13:13 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
selectors: [
|
|
|
|
'.dropdown-menu-content',
|
|
|
|
'.dropdown.active .dropdown-menu-content',
|
|
|
|
'.dropdown-menu-content.anim-scale-in'
|
|
|
|
],
|
|
|
|
message: `The "dropdown-menu-content" class is unnecessary.`
|
2019-09-05 21:13:45 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2019-09-05 22:37:14 +03:00
|
|
|
const {version: CURRENT_VERSION} = require('./package.json')
|
2019-09-05 21:55:10 +03:00
|
|
|
const semver = require('semver')
|
|
|
|
|
2019-09-05 21:13:45 +03:00
|
|
|
// map selectors to the version and message of their deprecation
|
|
|
|
const selectorDeprecations = new Map()
|
2019-11-01 01:48:16 +03:00
|
|
|
const variableDeprecations = new Map()
|
2019-09-05 21:55:10 +03:00
|
|
|
for (const [version, deps] of Object.entries(versionDeprecations)) {
|
2019-11-01 01:48:16 +03:00
|
|
|
for (const {selectors = [], variables = [], message} of deps) {
|
2019-09-05 21:13:45 +03:00
|
|
|
for (const selector of selectors) {
|
|
|
|
selectorDeprecations.set(selector, {version, message})
|
|
|
|
}
|
2019-11-01 01:48:16 +03:00
|
|
|
for (const variable of variables) {
|
|
|
|
variableDeprecations.set(variable, {version, message})
|
|
|
|
}
|
2019-09-05 21:13:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSelectorDeprecated(selector, version = CURRENT_VERSION) {
|
2019-09-05 22:33:11 +03:00
|
|
|
const deprecation = selectorDeprecations.get(selector)
|
|
|
|
return deprecation ? semver.gte(deprecation.version, version) : false
|
2019-09-05 21:13:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-01 01:48:16 +03:00
|
|
|
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
|
|
|
|
}
|