Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prefix to examples #25

Merged
merged 2 commits into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions body-template.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
##### Examples

{{#each rule.optionExamples }}
{{{json . false}}}
{{{json . false ../rule.ruleName }}}
{{/each}}
{{/if}}

{{#if rule.options }}
##### Schema

{{{json rule.options true }}}
{{{json rule.options true '' }}}
{{/if}}

For more information see [this page](https://palantir.github.io/tslint/rules/{{{rule.ruleName}}}).
For more information see [this page](https://palantir.github.io/tslint/rules/{{{rule.ruleName}}}).
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@
"lodash": "^4.17.4",
"rxjs": "^5.3.0",
"tslint": "5.0.0",
"tslint-config-airbnb": "^5.0.0",
"tslint-config-standard": "^5.0.2",
"tslint-eslint-rules": "^4.0.0"
"tslint-eslint-rules": "^4.0.0",
"tslint-react": "^3.0.0"
}
}
6 changes: 4 additions & 2 deletions src/contentRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import * as path from 'path';
import * as fs from 'fs';
import * as handlebars from 'handlebars';
import {IRuleMetadata} from 'tslint';
import * as _ from 'lodash';
const autobind: any = require('autobind-decorator');

handlebars.registerHelper('notesHeader', (rule: IRuleMetadata) => {
return (rule.typescriptOnly || rule.hasFix || rule.requiresTypeInfo) ? `\n##### Notes\n` : '';
});
handlebars.registerHelper('json', (obj: any, escape: boolean = false) => {
handlebars.registerHelper('json', (obj: any, escape: boolean = false, prefix: string) => {
const json = escape ? JSON.stringify(obj, null, 2) : obj;
return '```json\n' + json + '\n```';
const prefixString = !_.isEmpty(prefix) ? '"' + prefix + '": ' : '';
return '```json\n' + prefixString + json + '\n```';
});

@autobind
Expand Down
5 changes: 3 additions & 2 deletions src/test/contentRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ContentRenderer', () => {
requiresTypeInfo: true,
typescriptOnly: true
};
const optionExamples = rule.optionExamples.map(o => '```json\n' + o + '\n```').join('\n');
const optionExamples = rule.optionExamples.map(o => '```json\n' + '"' + rule.ruleName + '": ' + o + '\n```').join('\n');
const options = '```json\n' + JSON.stringify(rule.options, null, 2) + '\n```';
const expected = `# Rule: ${rule.ruleName}

Expand Down Expand Up @@ -60,7 +60,8 @@ ${optionExamples}

${options}

For more information see [this page](https://palantir.github.io/tslint/rules/${rule.ruleName}).`;
For more information see [this page](https://palantir.github.io/tslint/rules/${rule.ruleName}).
`;
// When
const actual = renderer.render(rule);
// Then
Expand Down
Loading