test(aio): enable linting of `transforms/` and add rules for jasmine

This commit is contained in:
Georgios Kalpakas 2017-04-01 21:34:10 +03:00 committed by Pete Bacon Darwin
parent a562c64ed6
commit 62f9738a9a
41 changed files with 101 additions and 96 deletions

View File

@ -9,8 +9,8 @@
"ng": "yarn check-env && ng",
"start": "yarn check-env && ng serve",
"build": "yarn check-env && yarn docs && ng build -prod -sm",
"lint": "yarn check-env && yarn docs-lint && ng lint",
"test": "yarn check-env && ng test --sourcemap=false",
"lint": "yarn check-env && ng lint",
"pree2e": "yarn ~~update-webdriver",
"e2e": "yarn check-env && ng e2e --no-webdriver-update",
"deploy-preview": "scripts/deploy-preview.sh",
@ -18,6 +18,7 @@
"check-env": "node ../tools/check-environment.js",
"predocs": "rimraf src/content",
"docs": "dgeni ./transforms/angular.io-package",
"docs-lint": "eslint --ignore-path=\"transforms/.eslintignore\" transforms",
"docs-test": "node ../dist/tools/cjs-jasmine/index-tools ../../transforms/**/*.spec.js",
"~~update-webdriver": "webdriver-manager update --standalone false --gecko false",
"pre~~deploy": "yarn build",
@ -53,6 +54,8 @@
"dgeni": "^0.4.7",
"dgeni-packages": "0.17.0",
"entities": "^1.1.1",
"eslint": "^3.19.0",
"eslint-plugin-jasmine": "^2.2.0",
"firebase-tools": "^3.2.1",
"fs-extra": "^2.1.1",
"globby": "^6.1.0",

View File

@ -0,0 +1 @@
**/*.template.js

View File

@ -0,0 +1,20 @@
module.exports = {
'env': {
'es6': true,
'jasmine': true,
'node': true
},
'extends': [
'eslint:recommended',
'plugin:jasmine/recommended'
],
'plugins': [
'jasmine'
],
'rules': {
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always']
}
};

View File

@ -29,8 +29,7 @@ const DOCS_OUTPUT_PATH = path.resolve(OUTPUT_PATH, 'docs');
module.exports =
new Package(
'angular.io',
[
'angular.io', [
jsdocPackage, nunjucksPackage, typescriptPackage, linksPackage, examplesPackage,
gitPackage, targetPackage, contentPackage, rhoPackage
])
@ -59,7 +58,7 @@ module.exports =
.factory(require('./readers/json'))
.factory(require('./services/copyFolder'))
.config(function(checkAnchorLinksProcessor, log) {
.config(function(checkAnchorLinksProcessor) {
// TODO: re-enable
checkAnchorLinksProcessor.$enabled = false;
})
@ -257,7 +256,6 @@ module.exports =
generateKeywordsProcessor) {
const API_SEGMENT = 'api';
const GUIDE_SEGMENT = 'guide';
const APP_SEGMENT = 'app';
generateApiListDoc.outputFolder = API_SEGMENT;

View File

@ -1,7 +1,7 @@
module.exports = {
name: 'a',
description: 'A shorthand for creating heading anchors. Usage: `{@a some-id}`',
handler: function(doc, tagName, tagDescription, docs) {
handler: function(doc, tagName, tagDescription) {
return '<a id="' + tagDescription.trim() + '"></a>';
}
};

View File

@ -2,13 +2,12 @@ var testPackage = require('../../helpers/test-package');
var Dgeni = require('dgeni');
describe('addNotYetDocumentedProperty', function() {
var dgeni, injector, processor, log;
var dgeni, injector, processor;
beforeEach(function() {
dgeni = new Dgeni([testPackage('angular.io-package')]);
injector = dgeni.configureInjector();
processor = injector.get('addNotYetDocumentedProperty');
log = injector.get('log');
});
it('should mark export docs with no description as "not yet documented"', function() {

View File

@ -1,6 +1,5 @@
var testPackage = require('../../helpers/test-package');
var Dgeni = require('dgeni');
var path = require('canonical-path');
describe('checkUnbalancedBackTicks', function() {
var dgeni, injector, processor, log;

View File

@ -5,7 +5,7 @@ module.exports = function convertToJsonProcessor() {
$runBefore: ['writeFilesProcessor'],
docTypes: [],
$process: function(docs) {
const docTypes = this.docTypes
const docTypes = this.docTypes;
docs.forEach((doc) => {
if (docTypes.indexOf(doc.docType) !== -1) {
const output = {

View File

@ -2,7 +2,7 @@ const testPackage = require('../../helpers/test-package');
const Dgeni = require('dgeni');
const factory = require('./copyContentAssets');
fdescribe('extractDecoratedClasses processor', function() {
describe('extractDecoratedClasses processor', function() {
let dgeni, injector, processor;
beforeEach(function() {

View File

@ -9,5 +9,5 @@ module.exports = function filterIgnoredDocs() {
$process: function(docs) {
return docs.filter(doc => !this.ignore.some(regexp => regexp.test(doc.id)));
}
}
};
};

View File

@ -13,7 +13,7 @@ describe('filterIgnoredDocs processor', () => {
it('should run before the correct processor', () => {
const processor = processorFactory();
expect(processor.$runBefore).toEqual(['computing-paths'])
expect(processor.$runBefore).toEqual(['computing-paths']);
});
it('should run after the correct processor', () => {
@ -35,5 +35,5 @@ describe('filterIgnoredDocs processor', () => {
{ id: 'public1'},
{ id: 'public2'}
]);
})
});
});

View File

@ -3,5 +3,5 @@ module.exports = function filterMemberDocs() {
$runAfter: ['extra-docs-added'], $runBefore: ['computing-paths'], $process: function(docs) {
return docs.filter(function(doc) { return doc.docType !== 'member'; });
}
}
};
};

View File

@ -3,7 +3,7 @@ module.exports = function filterPrivateDocs() {
$runAfter: ['extra-docs-added'],
$runBefore: ['computing-paths'],
$process: function(docs) {
return docs.filter(function(doc) { return doc.privateExport !== true });
return docs.filter(function(doc) { return doc.privateExport !== true; });
}
}
};
};

View File

@ -13,7 +13,7 @@ describe('filterPrivateDocs processor', () => {
it('should run before the correct processor', () => {
const processor = processorFactory();
expect(processor.$runBefore).toEqual(['computing-paths'])
expect(processor.$runBefore).toEqual(['computing-paths']);
});
it('should run after the correct processor', () => {
@ -36,5 +36,5 @@ describe('filterPrivateDocs processor', () => {
{ name: 'public2'},
{ id: 'other'}
]);
})
});
});

View File

@ -13,7 +13,7 @@ describe('fixInternalDocumentLinks processor', () => {
it('should run before the correct processor', () => {
const processor = processorFactory();
expect(processor.$runBefore).toEqual(['writeFilesProcessor'])
expect(processor.$runBefore).toEqual(['writeFilesProcessor']);
});
it('should run after the correct processor', () => {
@ -48,5 +48,5 @@ describe('fixInternalDocumentLinks processor', () => {
`
},
]);
})
});
});

View File

@ -18,7 +18,7 @@ describe('generateApiListDoc processor', () => {
const docs = [
{ name: 'ɵPrivate' },
{ name: 'public' }
]
];
processor.$process(docs);
expect(docs[0].privateExport).toBeTruthy();

View File

@ -5,7 +5,7 @@ var _ = require('lodash');
* @description
*
*/
module.exports = function matchUpDirectiveDecoratorsProcessor(aliasMap) {
module.exports = function matchUpDirectiveDecoratorsProcessor() {
return {
$runAfter: ['ids-computed', 'paths-computed'],
@ -17,7 +17,7 @@ module.exports = function matchUpDirectiveDecoratorsProcessor(aliasMap) {
if (doc.docType === 'directive') {
doc.selector = doc.directiveOptions.selector;
for (decoratorName in decoratorMappings) {
for (let decoratorName in decoratorMappings) {
var propertyName = decoratorMappings[decoratorName];
doc[propertyName] =
getDecoratorValues(doc.directiveOptions[propertyName], decoratorName, doc.members);
@ -29,7 +29,6 @@ module.exports = function matchUpDirectiveDecoratorsProcessor(aliasMap) {
};
function getDecoratorValues(classDecoratorValues, memberDecoratorName, members) {
var optionMap = {};
var decoratorValues = {};
// Parse the class decorator

View File

@ -1,5 +1,3 @@
var _ = require('lodash');
module.exports = function mergeDecoratorDocs(log) {
return {
$runAfter: ['processing-docs'],

View File

@ -19,6 +19,7 @@ module.exports = function processNavigationMap(versionInfo, log) {
if (errors.length) {
log.error(`Navigation doc: ${navigationDoc.fileInfo.relativePath} contains invalid urls`);
// eslint-disable-next-line no-console
console.log(errors);
// TODO(petebd): fail if there are errors: throw new Error('processNavigationMap failed');
}
@ -26,7 +27,7 @@ module.exports = function processNavigationMap(versionInfo, log) {
// Add in the version data in a "secret" field to be extracted in the docs app
navigationDoc.data['__versionInfo'] = versionInfo.currentVersion;
}
}
};
};
function walk(node, map, path) {

View File

@ -1,4 +1,4 @@
module.exports = function(encodeCodeBlock) {
module.exports = function() {
// var MIXIN_PATTERN = /\S*\+\S*\(.*/;
return {
name: 'indentForMarkdown',
@ -57,6 +57,6 @@ module.exports = function(encodeCodeBlock) {
str += ' ';
}
return str;
};
}
};

View File

@ -1,5 +1,5 @@
module.exports = function() {
return {
name: 'internal', transforms: function() { return true; }
}
};
};

View File

@ -21,7 +21,7 @@ module.exports = new Package('content', [jsdocPackage, linksPackage])
})
// Configure ids and paths
.config(function(computeIdsProcessor, computePathsProcessor) {
.config(function(computeIdsProcessor) {
computeIdsProcessor.idTemplates.push({
docTypes: ['content'],

View File

@ -1,5 +1,3 @@
var path = require('canonical-path');
/**
* @dgService
* @description

View File

@ -1,11 +0,0 @@
module.exports = {
'globals': {'describe': true, 'beforeEach': true, 'it': true, 'expect': true},
'env': {'node': true},
'extends': 'eslint:recommended',
'rules': {
'indent': ['error', 2],
'linebreak-style': ['error', 'unix'],
'quotes': ['error', 'single'],
'semi': ['error', 'always']
}
};

View File

@ -4,7 +4,7 @@
* Later on we can extract the regions, via "shredding"; and we can also construct runnable examples
* for passing to plunker and the like.
*/
module.exports = function exampleFileReader(log) {
module.exports = function exampleFileReader() {
return {
name: 'exampleFileReader',
getDocs: function(fileInfo) {

View File

@ -1,5 +1,3 @@
var path = require('canonical-path');
var fs = require('fs');
var entities = require('entities');
/**
@ -28,7 +26,7 @@ module.exports = function exampleInlineTagDef(parseArgString, createDocMessage,
if (regionName === '\'\'') regionName = '';
var title = tagArgs.title || (unnamedArgs.length > 2 ? unnamedArgs.slice(2).join(' ') : null);
var linenums = tagArgs.linenums;
var stylePattern = tagArgs.stylePattern; // TODO: not yet implemented here
// var stylePattern = tagArgs.stylePattern; // TODO: not yet implemented here
const sourceCode = getExampleRegion(doc, relativePath, regionName);

View File

@ -14,8 +14,7 @@ var fs = require('fs');
* -titles="Hello app1, Hello app2" }
* @kind function
*/
module.exports = function exampleTabsInlineTagDef(
getLinkInfo, parseArgString, createDocMessage, log) {
module.exports = function exampleTabsInlineTagDef(getLinkInfo, parseArgString) {
return {
name: 'exampleTabs',
description:
@ -32,9 +31,10 @@ module.exports = function exampleTabsInlineTagDef(
}
// TODO: not yet implemented here
var stylePatterns = tagArgs.stylePattern;
// var stylePatterns = tagArgs.stylePattern;
var mixinPaths = relativePaths.map(function(relativePath, ix) {
// eslint-disable-next-line no-undef
var fragFileName = getApiFragmentFileName(relativePath, regions && regions[ix]);
if (!fs.existsSync(fragFileName)) {
// TODO: log.warn(createDocMessage('Invalid example (unable to locate fragment file: ' +
@ -43,7 +43,7 @@ module.exports = function exampleTabsInlineTagDef(
return path.join('_api', relativePath);
});
var comma = ', '
var comma = ', ';
var pathsArg = quote(mixinPaths.join(','));
var regionsArg = regions ? quote(regions.join(',')) : 'null';
var titlesArg = titles ? quote(titles) : 'null';

View File

@ -65,7 +65,7 @@ module.exports = function collectExamples(exampleMap, regionParser, log, createD
function createRegionDoc(folder, relativePath, regionName, regionContents) {
const path = folder + '/' + relativePath;
const id = path + '#' + regionName
const id = path + '#' + regionName;
return {
docType: 'example-region',
path: path,

View File

@ -8,7 +8,7 @@ describe('collectExampleRegions processor', () => {
beforeEach(function() {
regionParser = jasmine.createSpy('regionParser').and.callFake(function(contents, extension) {
return { contents: 'PARSED:' + contents, regions: {dummy: extension} }
return { contents: 'PARSED:' + contents, regions: {dummy: extension} };
});
const dgeni =
@ -82,7 +82,7 @@ describe('collectExampleRegions processor', () => {
createDoc('Other doc 2', 'other/b/c.js', 'content')
];
const processedDocs = processor.$process(docs);
processor.$process(docs);
expect(regionParser).toHaveBeenCalledTimes(3);
expect(regionParser).toHaveBeenCalledWith('Example A', 'js');

View File

@ -1,9 +1,8 @@
var testPackage = require('../../helpers/test-package');
var Dgeni = require('dgeni');
var path = require('path');
describe('renderExamples processor', () => {
var injector, processor, exampleMap, regionParser, collectExamples, exampleMap;
var injector, processor, exampleMap, collectExamples;
beforeEach(function() {
const dgeni = new Dgeni([testPackage('examples-package', true)]);
@ -24,7 +23,7 @@ describe('renderExamples processor', () => {
});
it('should run before the correct processor', () => {
expect(processor.$runBefore).toEqual(['writing-files'])
expect(processor.$runBefore).toEqual(['writing-files']);
});
it('should run after the correct processor', () => {

View File

@ -47,12 +47,12 @@ module.exports = function parseArgString() {
key = key.substr(1);
}
} else {
unnammedArgs.push(arg)
unnammedArgs.push(arg);
key = null;
}
}
}
} while (match !== null);
return args;
}
}
};
};

View File

@ -3,7 +3,6 @@ const html = require('./region-matchers/html');
const inlineC = require('./region-matchers/inline-c');
const inlineCOnly = require('./region-matchers/inline-c-only');
const inlineHash = require('./region-matchers/inline-hash');
const NO_NAME_REGION = '';
const DEFAULT_PLASTER = '. . .';
const {mapObject} = require('../utils');

View File

@ -172,7 +172,7 @@ describe('regionParser service', () => {
expect(output.regions['A']).toEqual(t('abc', 'xyz'));
expect(output.regions['B']).toEqual(t('abc'));
expect(output.regions['C']).toEqual(t('xyz'));
})
});
});
function t() {

View File

@ -17,7 +17,7 @@ module.exports = {
*/
parseAttributes(str) {
const attrMap = {};
let index = 0, key, value;
let index = 0;
skipSpace();
@ -64,7 +64,7 @@ module.exports = {
function tryQuote() {
const quote = str[index];
if (['"', "'"].indexOf(quote) !== -1) {
if (['"', '\''].indexOf(quote) !== -1) {
index++;
return quote;
}

View File

@ -71,6 +71,6 @@ describe('utils', () => {
expect(() => parseAttributes('a="" b="two')).toThrowError(
'Unterminated quoted attribute value in `a="" b="two`. Starting at 8. Expected a " but got "end of string".'
);
})
});
});
});

View File

@ -19,7 +19,7 @@ module.exports = function testPackage(packageName, mockTemplateEngine) {
// overrides base packageInfo and returns the one for the 'angular/angular' repo.
const PROJECT_ROOT = path.resolve(__dirname, '../../..');
pkg.factory('packageInfo', function() { return require(path.resolve(PROJECT_ROOT, 'package.json')); })
pkg.factory('packageInfo', function() { return require(path.resolve(PROJECT_ROOT, 'package.json')); });
if (mockTemplateEngine) {

View File

@ -4,7 +4,7 @@ var _ = require('lodash');
* @dgService getDocFromAlias
* @description Get an array of docs that match this alias, relative to the originating doc.
*/
module.exports = function getDocFromAlias(aliasMap, log) {
module.exports = function getDocFromAlias(aliasMap) {
return function getDocFromAlias(alias, originatingDoc) {
var docs = aliasMap.getDocs(alias);

View File

@ -73,6 +73,6 @@ module.exports = function getLinkInfo(getDocFromAlias, encodeCodeBlock, log) {
}
return linkInfo;
};
}
};

View File

@ -55,7 +55,7 @@ module.exports = function renderMarkdown() {
walk.startFrom(endIdx + 2);
return true;
};
}
renderMarkdownImpl.unformattedTags = [];
@ -64,5 +64,5 @@ module.exports = function renderMarkdown() {
function renderMarkdownImpl(content) {
const rawHtml = new rho.BlockCompiler(rho.options).toHtml(content);
return prettyPrint(rawHtml, { indent_size: 2, max_char: 0, unformatted: [...defaultUnformattedTags, ...renderMarkdownImpl.unformattedTags]});
};
}
};

View File

@ -12,7 +12,7 @@ module.exports = function targetEnvironments() {
var updateActiveCount = function() {
_activeCount = 0;
for (target in _targets) {
for (let target in _targets) {
if (_targets[target]) _activeCount++;
}
};

View File

@ -1963,6 +1963,10 @@ escope@^3.6.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"
eslint-plugin-jasmine@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.2.0.tgz#7135879383c39a667c721d302b9f20f0389543de"
eslint@^3.19.0:
version "3.19.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.19.0.tgz#c8fc6201c7f40dd08941b87c085767386a679acc"