in scripts/docs.js [160:216]
function _createRule(ruleName) {
// create basic rule object
var rule = {
ruleName: ruleName
};
// add paths
rule.sourcePath = templates.ruleSourcePath(rule);
rule.documentationPath = templates.ruleDocumentationPath(rule);
rule.examplesPath = templates.ruleExamplesPath(rule);
// parse rule comments
var mainRuleComment = parseComments(fs.readFileSync(rule.sourcePath).toString())[0];
// set lead, description, linkDescription and styleguideReferences
rule.lead = mainRuleComment.lead;
rule.description = mainRuleComment.description.trim();
rule.linkDescription = mainRuleComment.linkDescription ? mainRuleComment.linkDescription : rule.lead;
rule.styleguideReferences = mainRuleComment.styleguideReferences || [];
rule.version = mainRuleComment.version;
rule.category = mainRuleComment.category || 'uncategorizedRule';
rule.deprecated = !!mainRuleComment.deprecated;
rule.sinceAngularVersion = mainRuleComment.sinceAngularVersion;
if (rule.deprecated) {
rule.deprecationReason = mainRuleComment.deprecated;
rule.category = 'deprecatedRule';
}
if (!rule.version) {
throw new Error('No @version found for ' + ruleName);
}
// load rule module for tests
rule.module = require('../rules/' + rule.ruleName);// eslint-disable-line global-require
// load examples, prepare them for the tests and group the for the template
rule.allExamples = _loadExamples(rule);
rule.examples = {
valid: _filterByValidity(rule.allExamples, true),
invalid: _filterByValidity(rule.allExamples, false)
};
rule.groupedExamples = [];
var examplesGroupedByConfig = _.groupBy(rule.allExamples, 'jsonOptions');
_.each(examplesGroupedByConfig, function(examples, config) {
// append invalid examples if existing
_appendGroupedExamplesByValidity(rule.groupedExamples, examples, config, false);
// append valid examples if existing
_appendGroupedExamplesByValidity(rule.groupedExamples, examples, config, true);
});
rule.hasOnlyOneConfig = Object.keys(examplesGroupedByConfig).length === 1;
return rule;
}