Skip to content

Commit

Permalink
Fix: Migrate to new isSupported utility based on MDN data
Browse files Browse the repository at this point in the history
  • Loading branch information
antross committed Apr 29, 2019
1 parent a70d60d commit e76e864
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
11 changes: 3 additions & 8 deletions packages/hint-disown-opener/src/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { URL } from 'url';

import { debug as d } from '@hint/utils/dist/src/debug';
import { isSupported } from '@hint/utils/dist/src/caniuse';
import { isSupported } from '@hint/utils/dist/src/compat';
import { isRegularProtocol } from '@hint/utils/dist/src/network/is-regular-protocol';
import { HTMLElement } from '@hint/utils/dist/src/dom/html';
import { cutString } from '@hint/utils/dist/src/misc/cut-string';
Expand Down Expand Up @@ -120,12 +120,6 @@ export default class DisownOpenerHint implements IHint {
return;
}

/*
* TODO: In the future, change this to not use caniuse data.
* https://github.com/webhintio/hint/issues/30
*/

const targetedBrowsers: string = context.targetedBrowsers.join();
const relValuesToCheckFor: string[] = ['noopener'];

/*
Expand All @@ -134,7 +128,8 @@ export default class DisownOpenerHint implements IHint {
* also check for 'noreferrer'.
*/

if (!targetedBrowsers || !isSupported('rel-noopener', targetedBrowsers)) {
// TODO: Fix `isSupported` so `element` can be `a`.
if (!context.targetedBrowsers.length || !isSupported({ attribute: 'rel', element: 'link', value: 'noopener' }, context.targetedBrowsers)) {
relValuesToCheckFor.push('noreferrer');
}

Expand Down
8 changes: 4 additions & 4 deletions packages/hint-manifest-is-valid/src/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
IHint,
IJSONLocationFunction
} from 'hint/dist/src/lib/types';
import { isSupported } from '@hint/utils/dist/src/caniuse';
import { isSupported } from '@hint/utils/dist/src/compat';
import { normalizeString } from '@hint/utils/dist/src/misc/normalize-string';
import {
Manifest,
Expand All @@ -40,8 +40,6 @@ export default class ManifestIsValidHint implements IHint {

public constructor(context: HintContext<ManifestEvents>) {

const targetedBrowsers: string = context.targetedBrowsers.join();

const isNotSupportedColorValue = (color: ColorDescriptor, normalizedColorValue: string): boolean => {
const hexWithAlphaRegex = /^#([0-9a-fA-F]{4}){1,2}$/;

Expand All @@ -62,10 +60,12 @@ export default class ManifestIsValidHint implements IHint {
* * https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/graphics/Color.cpp?rcl=6263bcf0ec9f112b5f0d84fc059c759302bd8c67
*/

// TODO: Use `isSupported` for all color syntax checks.

// `RGBA` support depends on the browser.
return (color.model === 'rgb' &&
hexWithAlphaRegex.test(normalizedColorValue) &&
!isSupported('css-rrggbbaa', targetedBrowsers)) ||
!isSupported({ property: 'color', value: '#00000000' }, context.targetedBrowsers)) ||

// `HWB` is not supported anywhere (?).
color.model === 'hwb';
Expand Down
9 changes: 4 additions & 5 deletions packages/hint-meta-theme-color/src/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import {
IHint,
TraverseEnd
} from 'hint';
import { caniuse, HTMLElement, misc } from '@hint/utils';
import { HTMLElement, isSupported, misc } from '@hint/utils';

import meta from './meta';

const { isSupported } = caniuse;
const { normalizeString } = misc;
/*
* ------------------------------------------------------------------------------
Expand All @@ -35,8 +34,6 @@ export default class MetaThemeColorHint implements IHint {

public constructor(context: HintContext) {

const targetedBrowsers: string = context.targetedBrowsers.join();

let bodyElementWasReached: boolean = false;
let firstThemeColorMetaElement: HTMLElement;

Expand Down Expand Up @@ -68,10 +65,12 @@ export default class MetaThemeColorHint implements IHint {
* * https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/graphics/Color.cpp?rcl=6263bcf0ec9f112b5f0d84fc059c759302bd8c67
*/

// TODO: Use `isSupported` for all color syntax checks.

// `RGBA` support depends on the browser.
return (color.model === 'rgb' &&
hexWithAlphaRegex.test(normalizedColorValue) &&
!isSupported('css-rrggbbaa', targetedBrowsers)) ||
!isSupported({ property: 'color', value: '#00000000' }, context.targetedBrowsers)) ||

// `HWB` is not supported anywhere (?).
color.model === 'hwb';
Expand Down

0 comments on commit e76e864

Please sign in to comment.