Skip to content

Commit

Permalink
Fix: Update new-core-rule templates
Browse files Browse the repository at this point in the history
Fix #551
Close #560
  • Loading branch information
Anton Molleda authored and alrra committed Oct 2, 2017
1 parent f2e500d commit f5c0218
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/lib/cli/rules/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export type NewRule = {
/** Events that should be subscribed to */
events: string;
/** If the new rule is core */
isCore: boolean;
isRecommended: boolean;
/** Usage categories that the new rule applies to */
useCase?: UseCase;
};
24 changes: 15 additions & 9 deletions src/lib/cli/rules/new-core-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,29 @@ const useCases = [
const questions = [
{
default: 'newRule',
message: 'What\'s the name of this new rule?',
message: `What's the name of this new rule?`,
name: 'name',
type: 'input'
},
{
default: 'new awesome rule',
message: `What's the description of this new rule?`,
name: 'description',
type: 'input'
},
{
default: true,
message: 'Is it a recommended rule',
name: 'recommended',
type: 'confirm'
},
{
choices: categories,
default: Category.interoperability,
message: 'Please select the category of this new rule:',
name: 'category',
type: 'list'
},
{
default: 'new awesome rule',
message: 'What\'s the description of this new rule?',
name: 'description',
type: 'input'
},
{
choices: useCases,
default: 'dom',
Expand Down Expand Up @@ -213,7 +219,7 @@ export const newRule = async (actions: CLIOptions): Promise<boolean> => {
description: { string: '' },
elementType: '',
events: '',
isCore: false,
isRecommended: false,
name: '',
useCase: {
dom: false,
Expand All @@ -230,7 +236,7 @@ export const newRule = async (actions: CLIOptions): Promise<boolean> => {
rule.name = normalize(results.name, '-');
rule.description = escapeSafeString(results.description);
rule.category = results.category;
rule.isCore = results.isCore || true;
rule.isRecommended = results.recommended || false;
rule.useCase[results.useCase] = true;
rule.events = getEventsByUseCase(results.useCase);

Expand Down
13 changes: 7 additions & 6 deletions src/lib/cli/rules/templates/core-rule/rule-script.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* @fileoverview {{description}}
*/

// The list of types depends on the events you want to capture.
import { IRule, IRuleBuilder } from '../../types';
import { RuleContext } from '../../rule-context';
// The list of types depends on the events you want to capture.
import { IRule, IRuleBuilder, {{events}} } from '../../types';
import { debug as d } from '../../utils/debug';

import { {{events}} } from '../../types';
const debug: debug.IDebugger = d(__filename);

// ------------------------------------------------------------------------------
// Public
Expand Down Expand Up @@ -69,13 +70,13 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: `{{category}}`,
category: Category.{{category}},
description: `{{description}}`
},
recommended: {{isCore}},
recommended: {{#if isRecommended}}true{{else}}false{{/if}},
schema: [],
worksWithLocalFiles: false
}
}
};
module.exports = rule;
10 changes: 4 additions & 6 deletions src/lib/cli/rules/templates/core-rule/rule-test.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint sort-keys: 0, no-undefined: 0 */

import { IRuleTest } from '../../../helpers/rule-test-type'; // eslint-disable-line no-unused-vars
import { IRuleTest } from '../../../helpers/rule-test-type';
import { getRuleName } from '../../../../src/lib/utils/rule-helpers';
import * as ruleRunner from '../../../helpers/rule-runner';

Expand All @@ -9,11 +7,11 @@ const ruleName = getRuleName(__dirname);
const tests: Array<IRuleTest> = [
{
name: 'Name of the tests',
serverConfig: 'HTML to use',
reports: [{
message: 'Message the error will have',
position: { column: 0, line: 0 } // Where the error will show.
}]
position: { column: 0, line: 0 } // Where the error will appear
}],
serverConfig: 'HTML to use'
}
];

Expand Down
11 changes: 6 additions & 5 deletions tests/lib/cli/rules/fixtures/new-quotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* @fileoverview This is a \`description\` that contains 'single quote' and "double qutoes"
*/

// The list of types depends on the events you want to capture.
import { IRule, IRuleBuilder } from '../../types';
import { RuleContext } from '../../rule-context';
// The list of types depends on the events you want to capture.
import { IRule, IRuleBuilder, IFetchStart, IFetchEnd, IFetchError } from '../../types';
import { debug as d } from '../../utils/debug';

import { IFetchStart, IFetchEnd, IFetchError } from '../../types';
const debug: debug.IDebugger = d(__filename);

// ------------------------------------------------------------------------------
// Public
Expand Down Expand Up @@ -34,13 +35,13 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: `pwa`,
category: Category.pwa,
description: `This is a \`description\` that contains 'single quote' and "double qutoes"`
},
recommended: true,
schema: [],
worksWithLocalFiles: false
}
}
};

module.exports = rule;
11 changes: 6 additions & 5 deletions tests/lib/cli/rules/fixtures/new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* @fileoverview An important new rule
*/

// The list of types depends on the events you want to capture.
import { IRule, IRuleBuilder } from '../../types';
import { RuleContext } from '../../rule-context';
// The list of types depends on the events you want to capture.
import { IRule, IRuleBuilder, IFetchStart, IFetchEnd, IFetchError } from '../../types';
import { debug as d } from '../../utils/debug';

import { IFetchStart, IFetchEnd, IFetchError } from '../../types';
const debug: debug.IDebugger = d(__filename);

// ------------------------------------------------------------------------------
// Public
Expand Down Expand Up @@ -34,13 +35,13 @@ const rule: IRuleBuilder = {
},
meta: {
docs: {
category: `pwa`,
category: Category.pwa,
description: `An important new rule`
},
recommended: true,
schema: [],
worksWithLocalFiles: false
}
}
};

module.exports = rule;
8 changes: 4 additions & 4 deletions tests/lib/cli/rules/new-core-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ test.serial(`if core, 'generate' should call to write script, documentation, tes
description: 'An important new rule',
elementType: '',
extension: '',
isCore: true,
name: newRuleName,
recommended: true,
useCase: 'request'
};

Expand Down Expand Up @@ -121,8 +121,8 @@ test.serial(`The right script template should be used in 'generate'`, async (t)
description: 'An important new rule',
elementType: '',
extension: 'ts',
isCore: true,
name: newRuleName,
recommended: true,
useCase: 'request'
};

Expand All @@ -149,8 +149,8 @@ test.serial(`Description contains quotes`, async (t) => {
description: `This is a \`description\` that contains 'single quote' and "double qutoes"`,
elementType: '',
extension: 'ts',
isCore: true,
name: newRuleName,
recommended: true,
useCase: 'request'
};

Expand All @@ -177,8 +177,8 @@ test.serial(`Throw an error if a new rule already exists when calling 'generate'
description: 'An important new rule',
elementType: '',
extension: 'js',
isCore: true,
name: existingRuleName,
recommended: true,
useCase: 'request'
};

Expand Down

0 comments on commit f5c0218

Please sign in to comment.