Skip to content

Commit

Permalink
Chore: Create enum for rule category
Browse files Browse the repository at this point in the history
Also, remove unused `fixable` field.

Close #542
  • Loading branch information
sarvaje authored and alrra committed Sep 28, 2017
1 parent 8138ee4 commit 5fc30ee
Show file tree
Hide file tree
Showing 30 changed files with 84 additions and 71 deletions.
13 changes: 7 additions & 6 deletions docs/developer-guide/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ related to this new rule. A complete list of the questions is shown below:

* What's the name of this new rule?
* Please select the category of this new rule:
* Accessibility
* Interoperability
* Performance
* PWAs
* Security
* accessibility
* interoperability
* performance
* pwa
* security
* What's the description of this new rule?
* Please select the category of use case:
* DOM
Expand Down Expand Up @@ -128,6 +128,7 @@ The following is a basic template for a rule (`import` paths might change
depending on the rule type):

```ts
import { Category } from '../../enums/category';
import { IFetchEnd, IRule, IRuleBuilder } from '../../types';
import { RuleContext } from '../../rule-context';

Expand Down Expand Up @@ -200,7 +201,7 @@ Rules have an object `meta` that defines several properties:
```json
{
"docs": {
"category": "string",
"category": "Category",
"description": "string"
},
"recommended": "boolean", // If the rule is part of the recommended options
Expand Down
3 changes: 2 additions & 1 deletion src/lib/cli/rules/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { findPackageRoot as packageRoot, normalizeStringByDelimiter } from '../../utils/misc';
import { Category } from '../../enums/category';

export const normalize = normalizeStringByDelimiter;
export const ruleTemplateDir = './templates/core-rule';
Expand Down Expand Up @@ -31,7 +32,7 @@ export type NewRule = {
/** Name of the new rule */
name: string;
/** Category of the new rule */
category: string;
category: Category;
/** Description of the new rule */
description: hbs.SafeString;
/** Element type if `dom` is selected in useCase */
Expand Down
19 changes: 10 additions & 9 deletions src/lib/cli/rules/new-core-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as inquirer from 'inquirer';
import * as _ from 'lodash';
import * as mkdirp from 'mkdirp';

import { Category } from '../../enums/category';
import { CLIOptions } from '../../types';
import { debug as d } from '../../utils/debug';
import * as logger from '../../utils/logging';
Expand Down Expand Up @@ -130,13 +131,13 @@ const getEventsByUseCase = (useCase: string): string => {
};

/** List rule categories. */
const categories = [
{ name: 'Accessibility' },
{ name: 'Interoperability' },
{ name: 'Performance' },
{ name: 'PWAs' },
{ name: 'Security' }
];
const categories = [];

for (const enumValue in Category) {
if (Category.hasOwnProperty(enumValue)) {
categories.push({ name: Category[enumValue] });
}
}

/** List of different use cases of a rule. */
const useCases = [
Expand Down Expand Up @@ -168,7 +169,7 @@ const questions = [
},
{
choices: categories,
default: 'Interoperability',
default: Category.interoperability,
message: 'Please select the category of this new rule:',
name: 'category',
type: 'list'
Expand Down Expand Up @@ -208,7 +209,7 @@ export const newRule = async (actions: CLIOptions): Promise<boolean> => {
}

const rule: NewRule = {
category: '',
category: null,
description: { string: '' },
elementType: '',
events: '',
Expand Down
1 change: 0 additions & 1 deletion src/lib/cli/rules/templates/core-rule/rule-script.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const rule: IRuleBuilder = {
category: `{{category}}`,
description: `{{description}}`
},
fixable: 'code',
recommended: {{isCore}},
schema: [],
worksWithLocalFiles: false
Expand Down
7 changes: 7 additions & 0 deletions src/lib/enums/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum Category {
pwa = 'pwa',
accessibility = 'accessibility',
interoperability = 'interoperability',
security = 'security',
performance = 'performance'
}
4 changes: 2 additions & 2 deletions src/lib/rules/apple-touch-icons/apple-touch-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as url from 'url';

import * as getImageData from 'image-size';

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { isHTMLDocument, isRegularProtocol, normalizeString } from '../../utils/misc';
import { IAsyncHTMLDocument, IAsyncHTMLElement, ITraverseEnd, INetworkData } from '../../types';
Expand Down Expand Up @@ -272,10 +273,9 @@ const rule: IRuleBuilder = {

meta: {
docs: {
category: `PWAs`,
category: Category.pwa,
description: `Require an 'apple-touch-icon'`
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
6 changes: 3 additions & 3 deletions src/lib/rules/axe/axe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

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

import { readFileAsync } from '../../utils/misc';
import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { IAsyncHTMLElement, IRule, IRuleBuilder, Severity, ITraverseEnd } from '../../types';
import { readFileAsync } from '../../utils/misc';
import { RuleContext } from '../../rule-context';

const debug = d(__filename);
Expand Down Expand Up @@ -108,10 +109,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'accessibility',
category: Category.accessibility,
description: 'Runs axe-core tests in the target'
},
fixable: 'code',
recommended: true,
schema: [{
additionalProperties: false,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/content-type/content-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import * as isSvg from 'is-svg';
import * as mimeDB from 'mime-db';
import { parse, MediaType } from 'content-type';

import { Category } from '../../enums/category';
import { IAsyncHTMLElement, IResponse, IRule, IRuleBuilder, IFetchEnd } from '../../types'; // eslint-disable-line no-unused-vars
import { isDataURI, normalizeString } from '../../utils/misc';
import { RuleContext } from '../../rule-context';
Expand Down Expand Up @@ -288,10 +289,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'interoperability',
category: Category.interoperability,
description: 'Require `Content-Type` header with appropriate value'
},
fixable: 'code',
recommended: true,
schema: [{
items: { type: 'string' },
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/disown-opener/disown-opener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isSupported } from 'caniuse-api';
import * as pluralize from 'pluralize';
import * as sameOrigin from 'same-origin';

import { Category } from '../../enums/category';
import { cutString, isRegularProtocol } from '../../utils/misc';
import { debug as d } from '../../utils/debug';
import { IAsyncHTMLElement, IElementFound, IRule, IRuleBuilder } from '../../types';
Expand Down Expand Up @@ -144,10 +145,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'security',
category: Category.security,
description: 'Require `noopener` (and `noreferrer`) on `a` and `area` element with target="_blank"'
},
fixable: 'code',
recommended: true,
schema: [{
additionalProperties: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Requirements
// ------------------------------------------------------------------------------

import { Category } from '../../enums/category';
import { IAsyncHTMLDocument, IAsyncHTMLElement, IRule, IRuleBuilder, ITraverseEnd } from '../../types';
import { isLocalFile, normalizeString } from '../../utils/misc';
import { RuleContext } from '../../rule-context';
Expand Down Expand Up @@ -185,10 +186,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'interoperability',
category: Category.interoperability,
description: 'Require highest available document mode'
},
fixable: 'code',
recommended: true,
schema: [{
additionalProperties: false,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/html-checker/html-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import * as _ from 'lodash';

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { RuleContext } from '../../rule-context';
import { IRule, IRuleBuilder, ITargetFetchEnd, IScanEnd, IProblemLocation, Severity } from '../../types';
Expand Down Expand Up @@ -141,10 +142,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'Interoperability',
category: Category.interoperability,
description: `Validate HTML using 'the Nu HTML checker'`
},
fixable: 'code',
recommended: true,
schema: [{
properties: {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/manifest-app-name/manifest-app-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

const { ucs2 } = require('punycode');

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { IManifestFetchEnd, IResponse, IRule, IRuleBuilder } from '../../types'; // eslint-disable-line no-unused-vars
import { RuleContext } from '../../rule-context';
Expand Down Expand Up @@ -119,10 +120,9 @@ const rule: IRuleBuilder = {

meta: {
docs: {
category: 'pwa',
category: Category.pwa,
description: 'Require web site/app name to be specified'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/manifest-exists/manifest-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Requirements
// ------------------------------------------------------------------------------

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { IAsyncHTMLElement, IElementFound, IManifestFetchEnd, IManifestFetchError, ITraverseEnd, IRule, IRuleBuilder } from '../../types'; // eslint-disable-line no-unused-vars
import { normalizeString } from '../../utils/misc';
Expand Down Expand Up @@ -81,10 +82,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'pwa',
category: Category.pwa,
description: 'Require a web app manifest'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import * as path from 'path';

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { IAsyncHTMLElement, IElementFound, IRule, IRuleBuilder } from '../../types'; // eslint-disable-line no-unused-vars
import { normalizeString } from '../../utils/misc';
Expand Down Expand Up @@ -44,10 +45,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'pwa',
category: Category.pwa,
description: 'Require `.webmanifest` as the file extension for the web app manifest file'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/manifest-is-valid/manifest-is-valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Requirements
// ------------------------------------------------------------------------------

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { IManifestFetchEnd, IResponse, IRule, IRuleBuilder } from '../../types'; // eslint-disable-line no-unused-vars
import { RuleContext } from '../../rule-context';
Expand Down Expand Up @@ -47,10 +48,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'pwa',
category: Category.pwa,
description: 'Require valid web app manifest'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/meta-charset-utf-8/meta-charset-utf-8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Requirements
// ------------------------------------------------------------------------------

import { Category } from '../../enums/category';
import { IAsyncHTMLDocument, IAsyncHTMLElement, IRule, IRuleBuilder, ITraverseEnd } from '../../types';
import { isHTMLDocument, normalizeString } from '../../utils/misc';
import { RuleContext } from '../../rule-context';
Expand Down Expand Up @@ -121,10 +122,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'misc',
category: Category.interoperability,
description: 'Require `<meta charset="utf-8">`'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/meta-viewport/meta-viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { parseMetaViewPortContent } from 'metaviewport-parser';

import { Category } from '../../enums/category';
import { isHTMLDocument, normalizeString } from '../../utils/misc';
import { IAsyncHTMLDocument, IAsyncHTMLElement, ITraverseEnd } from '../../types';
import { IRule, IRuleBuilder } from '../../types';
Expand Down Expand Up @@ -187,10 +188,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'misc',
category: Category.interoperability,
description: 'Require viewport meta tag'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: true
Expand Down
4 changes: 2 additions & 2 deletions src/lib/rules/no-disallowed-headers/no-disallowed-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import * as pluralize from 'pluralize';

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { getIncludedHeaders, mergeIgnoreIncludeArrays } from '../../utils/rule-helpers';
import { IAsyncHTMLElement, IFetchEnd, IRule, IRuleBuilder } from '../../types'; // eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -68,10 +69,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'security',
category: Category.security,
description: 'Disallow certain HTTP response headers'
},
fixable: 'code',
recommended: true,
schema: [{
additionalProperties: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import * as url from 'url';

import { Category } from '../../enums/category';
import { debug as d } from '../../utils/debug';
import { IFetchEnd, INetworkData, IResponse, ITraverseEnd, IRule, IRuleBuilder } from '../../types'; // eslint-disable-line no-unused-vars
import { isDataURI } from '../../utils/misc';
Expand Down Expand Up @@ -138,10 +139,9 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: 'interoperability',
category: Category.interoperability,
description: 'Disallow small error pages'
},
fixable: 'code',
recommended: true,
schema: [],
worksWithLocalFiles: false
Expand Down
Loading

0 comments on commit 5fc30ee

Please sign in to comment.