Eugenio Romano fe0ac0e474
move tslint ADF rules in principal repo (#3247)
* move tslint ADF rules in principal repo

* fix style issues

* change pacakge.json position

* update to angular cli 6.0.0

* reorganization package.json

* remove node modules2 folder

* exclude integration

* rollback alfresco-js-api

* solve types problems

* fix pdf test

* fix errors and exclude two tests

* fix e2e

* fix test

* copy all the new packages in node_modules

* fix test

* fix packaging script

* scss issue fix

* move test export in tools
2018-05-04 17:13:45 +01:00

54 lines
1.9 KiB
TypeScript

import * as ts from "typescript";
import * as Lint from "tslint";
export class Rule extends Lint.Rules.AbstractRule {
public static metadata: Lint.IRuleMetadata = {
ruleName: 'adf-file-name',
type: 'maintainability',
description: `Enforce consistent name avoid prefix`,
descriptionDetails: `See more at https://angular.io/styleguide#style-05-13.`,
rationale: `Consistent conventions make it easy to quickly identify files when you search with autocomplete.`,
options: null,
optionsDescription: "Not configurable.",
typescriptOnly: true,
};
public static FAILURE_STRING = 'The name of the File should not start with ADF Alfresco or Activiti prefix ';
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new AdfFileName(sourceFile, this.getOptions()));
}
}
// The walker takes care of all the work.
class AdfFileName extends Lint.RuleWalker {
public visitSourceFile(node: ts.SourceFile) {
var whiteList = ['activiti-alfresco.service.ts', 'activiti-alfresco.service.spec.ts',
'alfresco-api.service.ts', 'alfresco-api.service.spects'];
var fileName = this.getFilename();
var fileNameReg = /^(alfresco|activiti|adf|activity)/ig;
var filenameMatch = fileNameReg.exec(fileName);
var isWhiteListName = whiteList.find((currentWhiteListName) => {
return currentWhiteListName === fileName;
});
if (filenameMatch && !isWhiteListName) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + fileName));
super.visitSourceFile(node);
}
}
private getFilename(): string {
const filename = this.getSourceFile().fileName;
const lastSlash = filename.lastIndexOf('/');
if (lastSlash > -1) {
return filename.substring(lastSlash + 1);
}
return filename;
}
}