Skip to content

Commit

Permalink
New: Allow hint metadata to be imported separately
Browse files Browse the repository at this point in the history
Extracts existing `HintMetadata` objects into dedicated files and
adds a new `name` field to the `docs` property.

Allows hint metadata to be imported and bundled separately
from the implementation of a hint, reducing bundle size for
documentation scenarios.

Also updates all hint names for consistency both in the new
metadata and in the title of each associated `README`.
  • Loading branch information
antross authored and molant committed Nov 20, 2018
1 parent f3d1fab commit d40a0ab
Show file tree
Hide file tree
Showing 151 changed files with 1,318 additions and 902 deletions.
2 changes: 1 addition & 1 deletion packages/hint-amp-validator/README.md
@@ -1,4 +1,4 @@
# AMP HTML Validator (`amp-validator`)
# AMP HTML validator (`amp-validator`)

> AMP HTML is a way to build web pages that render with reliable and
fast performance. It is our attempt at fixing what many perceive as
Expand Down
20 changes: 4 additions & 16 deletions packages/hint-amp-validator/src/hint.ts
Expand Up @@ -4,11 +4,11 @@

import * as amphtmlValidator from 'amphtml-validator';

import { Category } from 'hint/dist/src/lib/enums/category';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
import { IHint, HintMetadata, FetchEnd } from 'hint/dist/src/lib/types';
import { IHint, FetchEnd } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';

import meta from './meta';

const debug: debug.IDebugger = d(__filename);

Expand All @@ -19,19 +19,7 @@ const debug: debug.IDebugger = d(__filename);
*/

export default class AmpValidatorHint implements IHint {
public static readonly meta: HintMetadata = {
docs: {
category: Category.performance,
description: `Require HTML page to be AMP valid.`
},
id: 'amp-validator',
schema: [{
additionalProperties: false,
properties: { 'errors-only': { type: 'boolean' } },
type: 'object'
}],
scope: HintScope.any
}
public static readonly meta = meta;

public constructor(context: HintContext) {
let validPromise: Promise<amphtmlValidator.Validator>;
Expand Down
20 changes: 20 additions & 0 deletions packages/hint-amp-validator/src/meta.ts
@@ -0,0 +1,20 @@
import { Category } from 'hint/dist/src/lib/enums/category';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
import { HintMetadata } from 'hint/dist/src/lib/types';

const meta: HintMetadata = {
docs: {
category: Category.performance,
description: `Require HTML page to be AMP valid.`,
name: 'AMP HTML validator'
},
id: 'amp-validator',
schema: [{
additionalProperties: false,
properties: { 'errors-only': { type: 'boolean' } },
type: 'object'
}],
scope: HintScope.any
};

export default meta;
2 changes: 1 addition & 1 deletion packages/hint-apple-touch-icons/README.md
@@ -1,4 +1,4 @@
# Require an apple touch icon (`apple-touch-icons`)
# Use Apple touch icon (`apple-touch-icons`)

`apple-touch-icons` requires that a single `180×180px` PNG
`apple-touch-icon` is used.
Expand Down
16 changes: 4 additions & 12 deletions packages/hint-apple-touch-icons/src/hint.ts
Expand Up @@ -6,13 +6,13 @@ import { URL } from 'url';

import * as getImageData from 'image-size';

import { Category } from 'hint/dist/src/lib/enums/category';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
import isRegularProtocol from 'hint/dist/src/lib/utils/network/is-regular-protocol';
import normalizeString from 'hint/dist/src/lib/utils/misc/normalize-string';
import { IAsyncHTMLDocument, IAsyncHTMLElement, IHint, TraverseEnd, NetworkData, HintMetadata } from 'hint/dist/src/lib/types';
import { IAsyncHTMLDocument, IAsyncHTMLElement, IHint, TraverseEnd, NetworkData } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';

import meta from './meta';

const debug: debug.IDebugger = d(__filename);

Expand All @@ -24,15 +24,7 @@ const debug: debug.IDebugger = d(__filename);

export default class AppleTouchIconsHint implements IHint {

public static readonly meta: HintMetadata = {
docs: {
category: Category.pwa,
description: `Require an 'apple-touch-icon'`
},
id: 'apple-touch-icons',
schema: [],
scope: HintScope.any
}
public static readonly meta = meta;

public constructor(context: HintContext) {

Expand Down
16 changes: 16 additions & 0 deletions packages/hint-apple-touch-icons/src/meta.ts
@@ -0,0 +1,16 @@
import { Category } from 'hint/dist/src/lib/enums/category';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
import { HintMetadata } from 'hint/dist/src/lib/types';

const meta: HintMetadata = {
docs: {
category: Category.pwa,
description: `Require an 'apple-touch-icon'`,
name: 'Use Apple touch icon'
},
id: 'apple-touch-icons',
schema: [],
scope: HintScope.any
};

export default meta;
2 changes: 1 addition & 1 deletion packages/hint-axe/README.md
@@ -1,4 +1,4 @@
# Accessibility assessment with aXe (`axe`)
# aXe accessibility check (`axe`)

`aXe` is the accessibility engine for automated testing of HTML-based
user interfaces. This hint performs the default accessibility tests
Expand Down
47 changes: 4 additions & 43 deletions packages/hint-axe/src/hint.ts
Expand Up @@ -11,12 +11,12 @@

import { AxeResults, Result as AxeResult, NodeResult as AxeNodeResult } from 'axe-core';

import { Category } from 'hint/dist/src/lib/enums/category';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
import { IAsyncHTMLElement, IHint, Severity, CanEvaluateScript, HintMetadata } from 'hint/dist/src/lib/types';
import { IAsyncHTMLElement, IHint, Severity, CanEvaluateScript } from 'hint/dist/src/lib/types';
import readFileAsync from 'hint/dist/src/lib/utils/fs/read-file-async';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';

import meta from './meta';

const debug = d(__filename);

Expand All @@ -28,46 +28,7 @@ const debug = d(__filename);

export default class AxeHint implements IHint {

public static readonly meta: HintMetadata = {
docs: {
category: Category.accessibility,
description: 'Runs axe-core tests in the target'
},
id: 'axe',
schema: [{
additionalProperties: false,
properties: {
rules: {
patternProperties: {
'^.+$': {
additionalProperties: false,
properties: { enabled: { type: 'boolean' } },
required: ['enabled'],
type: 'object'
}
},
type: 'object'
},
runOnly: {
additionalProperties: false,
properties: {
type: { type: 'string' },
values: {
items: { type: 'string' },
minItems: 1,
type: 'array',
uniqueItems: true
}
},
type: 'object'
}
}
}],
/*
* axe can not analize a file itself, it needs a connector.
*/
scope: HintScope.any
}
public static readonly meta = meta;

public constructor(context: HintContext) {

Expand Down
47 changes: 47 additions & 0 deletions packages/hint-axe/src/meta.ts
@@ -0,0 +1,47 @@
import { Category } from 'hint/dist/src/lib/enums/category';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
import { HintMetadata } from 'hint/dist/src/lib/types';

const meta: HintMetadata = {
docs: {
category: Category.accessibility,
description: 'Runs axe-core tests in the target',
name: 'aXe accessibility check'
},
id: 'axe',
schema: [{
additionalProperties: false,
properties: {
rules: {
patternProperties: {
'^.+$': {
additionalProperties: false,
properties: { enabled: { type: 'boolean' } },
required: ['enabled'],
type: 'object'
}
},
type: 'object'
},
runOnly: {
additionalProperties: false,
properties: {
type: { type: 'string' },
values: {
items: { type: 'string' },
minItems: 1,
type: 'array',
uniqueItems: true
}
},
type: 'object'
}
}
}],
/*
* axe can not analize a file itself, it needs a connector.
*/
scope: HintScope.any
};

export default meta;
2 changes: 1 addition & 1 deletion packages/hint-babel-config/docs/is-valid.md
@@ -1,4 +1,4 @@
# Babel configuration is valid (`is-valid`)
# Valid Babel configuration (`is-valid`)

## Why is this important?

Expand Down
16 changes: 4 additions & 12 deletions packages/hint-babel-config/src/is-valid.ts
@@ -1,14 +1,14 @@
/**
* @fileoverview `babel-config/is-valid` warns against providing an invalid babel configuration file.
*/
import { Category } from 'hint/dist/src/lib/enums/category';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
import { IHint, HintMetadata } from 'hint/dist/src/lib/types';
import { IHint } from 'hint/dist/src/lib/types';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';

import { BabelConfigEvents, BabelConfigInvalidJSON, BabelConfigInvalidSchema } from '@hint/parser-babel-config';

import meta from './meta/is-valid';

const debug: debug.IDebugger = d(__filename);

/*
Expand All @@ -17,15 +17,7 @@ const debug: debug.IDebugger = d(__filename);
* ------------------------------------------------------------------------------
*/
export default class BabelConfigIsValidHint implements IHint {
public static readonly meta: HintMetadata = {
docs: {
category: Category.development,
description: `'babel-config/is-valid' warns against providing an invalid babel configuration file \`.babelrc\``
},
id: 'babel-config/is-valid',
schema: [],
scope: HintScope.local
}
public static readonly meta = meta;

public constructor(context: HintContext<BabelConfigEvents>) {
const invalidJSONFile = async (babelConfigInvalid: BabelConfigInvalidJSON, event: string) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/hint-babel-config/src/meta.ts
@@ -0,0 +1,5 @@
/**
* @fileoverview Verify that the babel config is valid.
*/

module.exports = { 'is-valid': require('./meta/is-valid') };
16 changes: 16 additions & 0 deletions packages/hint-babel-config/src/meta/is-valid.ts
@@ -0,0 +1,16 @@
import { Category } from 'hint/dist/src/lib/enums/category';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
import { HintMetadata } from 'hint/dist/src/lib/types';

const meta: HintMetadata = {
docs: {
category: Category.development,
description: `'babel-config/is-valid' warns against providing an invalid babel configuration file \`.babelrc\``,
name: 'Valid Babel configuration'
},
id: 'babel-config/is-valid',
schema: [],
scope: HintScope.local
};

export default meta;
2 changes: 1 addition & 1 deletion packages/hint-content-type/README.md
@@ -1,4 +1,4 @@
# Require `Content-Type` HTTP response header with appropriate value (`content-type`)
# Correct `Content-Type` header (`content-type`)

`content-type` warns against not serving resources with the
`Content-Type` HTTP response header with a value containing
Expand Down
20 changes: 4 additions & 16 deletions packages/hint-content-type/src/hint.ts
Expand Up @@ -11,15 +11,15 @@

import { MediaType, parse } from 'content-type';

import { Category } from 'hint/dist/src/lib/enums/category';
import { debug as d } from 'hint/dist/src/lib/utils/debug';
import { IHint, FetchEnd, HintMetadata } from 'hint/dist/src/lib/types';
import { IHint, FetchEnd } from 'hint/dist/src/lib/types';
import getHeaderValueNormalized from 'hint/dist/src/lib/utils/network/normalized-header-value';
import isDataURI from 'hint/dist/src/lib/utils/network/is-data-uri';
import normalizeString from 'hint/dist/src/lib/utils/misc/normalize-string';
import { isTextMediaType } from 'hint/dist/src/lib/utils/content-type';
import { HintContext } from 'hint/dist/src/lib/hint-context';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';

import meta from './meta';

const debug = d(__filename);

Expand All @@ -31,19 +31,7 @@ const debug = d(__filename);

export default class ContentTypeHint implements IHint {

public static readonly meta: HintMetadata = {
docs: {
category: Category.interoperability,
description: 'Require `Content-Type` header with appropriate value'
},
id: 'content-type',
schema: [{
items: { type: 'string' },
type: ['object', 'null'],
uniqueItems: true
}],
scope: HintScope.site
}
public static readonly meta = meta;

public constructor(context: HintContext) {

Expand Down
20 changes: 20 additions & 0 deletions packages/hint-content-type/src/meta.ts
@@ -0,0 +1,20 @@
import { Category } from 'hint/dist/src/lib/enums/category';
import { HintScope } from 'hint/dist/src/lib/enums/hintscope';
import { HintMetadata } from 'hint/dist/src/lib/types';

const meta: HintMetadata = {
docs: {
category: Category.interoperability,
description: 'Require `Content-Type` header with appropriate value',
name: 'Correct `Content-Type` header'
},
id: 'content-type',
schema: [{
items: { type: 'string' },
type: ['object', 'null'],
uniqueItems: true
}],
scope: HintScope.site
};

export default meta;
2 changes: 1 addition & 1 deletion packages/hint-disown-opener/README.md
@@ -1,4 +1,4 @@
# Require external links to disown opener (`disown-opener`)
# External links disown opener (`disown-opener`)

`disown-opener` checks if the `rel` attribute is specified with both
the `noopener` and `noreferrer` values (or only `noopener` if all the
Expand Down

0 comments on commit d40a0ab

Please sign in to comment.