TSLint rules update

This commit is contained in:
sanex3339
2018-02-08 20:45:50 +03:00
parent c6cb82c1d0
commit e2e7c3d071
21 changed files with 107 additions and 69 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -22,11 +22,11 @@
"chalk": "2.3.0",
"chance": "1.0.13",
"class-validator": "0.8.1",
"commander": "2.13.0",
"commander": "2.14.0",
"escodegen-wallaby": "1.6.17",
"esprima": "4.0.0",
"estraverse": "4.2.0",
"inversify": "4.10.0",
"inversify": "^4.10.0",
"js-string-escape": "1.0.1",
"md5": "2.2.1",
"mkdirp": "0.5.1",
@@ -47,7 +47,7 @@
"@types/md5": "2.1.32",
"@types/mkdirp": "0.5.2",
"@types/mocha": "2.2.48",
"@types/node": "9.4.0",
"@types/node": "9.4.1",
"@types/rimraf": "2.0.2",
"@types/sinon": "4.1.3",
"@types/string-template": "1.0.2",
@@ -69,7 +69,7 @@
"tslint": "5.9.1",
"tslint-eslint-rules": "4.1.1",
"tslint-language-service": "0.9.8",
"tslint-webpack-plugin": "1.1.0",
"tslint-webpack-plugin": "1.1.1",
"typescript": "2.7.1",
"webpack": "3.10.0",
"webpack-node-externals": "1.6.0"
@@ -70,7 +70,7 @@ export class StackTraceAnalyzer implements IStackTraceAnalyzer {
/**
* @type {TCalleeDataExtractorFactory}
*/
private calleeDataExtractorFactory: TCalleeDataExtractorFactory;
private readonly calleeDataExtractorFactory: TCalleeDataExtractorFactory;
constructor (
@inject(ServiceIdentifiers.Factory__ICalleeDataExtractor) calleeDataExtractorFactory: TCalleeDataExtractorFactory
+1 -1
View File
@@ -17,7 +17,7 @@ export abstract class AbstractCustomNode implements ICustomNode {
/**
* @type {string[]}
*/
private static globalVariableTemplateFunctions: string[] = [
private static readonly globalVariableTemplateFunctions: string[] = [
GlobalVariableTemplate1(),
GlobalVariableTemplate2()
];
@@ -114,8 +114,8 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
: GlobalVariableNoEvalTemplate();
const atobPolyfill: string = format(AtobTemplate(), { globalVariableTemplate });
let decodeStringArrayTemplate: string = '',
selfDefendingCode: string = '';
let decodeStringArrayTemplate: string = '';
let selfDefendingCode: string = '';
if (this.options.selfDefending) {
selfDefendingCode = format(
@@ -40,7 +40,7 @@ export class StringArrayCustomNodeGroup extends AbstractCustomNodeGroup {
/**
* @type {IStorage <string>}
*/
private stringArrayStorage: IStorage <string>;
private readonly stringArrayStorage: IStorage <string>;
/**
* @param {TCustomNodeFactory} customNodeFactory
+4 -2
View File
@@ -1,13 +1,15 @@
/* tslint:disable:interface-name */
import * as escodegen from 'escodegen';
import * as ESTree from 'estree';
import { IGeneratorOutput } from '../interfaces/IGeneratorOutput';
declare module 'escodegen' {
export type XVerbatimProperty = {
export interface XVerbatimProperty {
content?: string;
precedence: escodegen.Precedence;
};
}
/**
* @param ast
@@ -12,7 +12,7 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
/**
* @type {number}
*/
private static baseIdentifierNameLength: number = 6;
private static readonly baseIdentifierNameLength: number = 6;
/**
* @type {Set<string>}
@@ -11,19 +11,19 @@ export class MangledIdentifierNamesGenerator extends AbstractIdentifierNamesGene
/**
* @type {string}
*/
private static initMangledNameCharacter: string = '9';
private static readonly initMangledNameCharacter: string = '9';
/**
* @type {string[]}
*/
private static nameSequence: string[] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
private static readonly nameSequence: string[] = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
/**
* Reserved JS words with length of 2-4 symbols that can be possible generated with this replacer
*
* @type {string[]}
*/
private static reservedNames: string[] = [
private static readonly reservedNames: string[] = [
'byte', 'case', 'char', 'do', 'else', 'enum', 'eval', 'for', 'goto',
'if', 'in', 'int', 'let', 'long', 'new', 'null', 'this', 'true', 'try',
'var', 'void', 'with'
+2 -2
View File
@@ -2,6 +2,6 @@ import * as estraverse from 'estraverse';
import * as ESTree from 'estree';
export interface IVisitor <T extends ESTree.Node = ESTree.Node> {
enter?: (node: T, parentNode: ESTree.Node | null) => ESTree.Node | estraverse.VisitorOption | void;
leave?: (node: T, parentNode: ESTree.Node | null) => ESTree.Node | estraverse.VisitorOption | void;
enter? (node: T, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption | void;
leave? (node: T, parentNode: ESTree.Node | null): ESTree.Node | estraverse.VisitorOption | void;
}
@@ -22,7 +22,7 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
/**
* @type {Map<VariableDeclarator, TNodeWithScope>}
*/
private cachedScopeNodesMap: Map <ESTree.VariableDeclarator, TNodeWithScope> = new Map();
private readonly cachedScopeNodesMap: Map <ESTree.VariableDeclarator, TNodeWithScope> = new Map();
/**
* @param {IRandomGenerator} randomGenerator
@@ -63,6 +63,33 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
return properties.filter((property: ESTree.Property, index: number) => !removablePropertyIds.includes(index));
}
/**
* @param {Property} propertyNode
* @returns {string | null}
*/
private static getPropertyNodeKeyName (propertyNode: ESTree.Property): string | null {
const propertyKeyNode: ESTree.Expression = propertyNode.key;
if (NodeGuards.isLiteralNode(propertyKeyNode) && typeof propertyKeyNode.value === 'string') {
return propertyKeyNode.value;
} else if (NodeGuards.isIdentifierNode(propertyKeyNode)) {
return propertyKeyNode.name;
}
return null;
}
/**
* @param {Expression | Pattern} propertyValueNode
* @returns {boolean}
*/
private static isValidPropertyValueNode (propertyValueNode: ESTree.Expression | ESTree.Pattern): propertyValueNode is ESTree.Expression {
return !NodeGuards.isObjectPatternNode(propertyValueNode)
&& !NodeGuards.isArrayPatternNode(propertyValueNode)
&& !NodeGuards.isAssignmentPatternNode(propertyValueNode)
&& !NodeGuards.isRestElementNode(propertyValueNode);
}
/**
* @param {TransformationStage} transformationStage
* @returns {IVisitor | null}
@@ -142,28 +169,19 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
for (let i: number = 0; i < propertiesLength; i++) {
const property: ESTree.Property = properties[i];
const propertyKey: ESTree.Expression = property.key;
const propertyValue: ESTree.Expression | ESTree.Pattern = property.value;
// invalid property nodes
if (
NodeGuards.isObjectPatternNode(property.value)
|| NodeGuards.isArrayPatternNode(property.value)
|| NodeGuards.isAssignmentPatternNode(property.value)
|| NodeGuards.isRestElementNode(property.value)
) {
if (!ObjectExpressionKeysTransformer.isValidPropertyValueNode(propertyValue)) {
continue;
}
/**
* Stage 1: collecting property node key names
* Stage 1: extract property node key names
*/
let propertyKeyName: string;
const propertyKeyName: string | null = ObjectExpressionKeysTransformer.getPropertyNodeKeyName(property);
if (NodeGuards.isLiteralNode(propertyKey) && typeof propertyKey.value === 'string') {
propertyKeyName = propertyKey.value;
} else if (NodeGuards.isIdentifierNode(propertyKey)) {
propertyKeyName = propertyKey.name;
} else {
if (!propertyKeyName) {
continue;
}
@@ -177,20 +195,15 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
: Nodes.getIdentifierNode(propertyKeyName);
const memberExpressionNode: ESTree.MemberExpression = Nodes
.getMemberExpressionNode(memberExpressionObject, memberExpressionProperty, true);
const rightExpression: ESTree.Expression = property.value;
const expressionStatementNode: ESTree.ExpressionStatement = Nodes.getExpressionStatementNode(
Nodes.getAssignmentExpressionNode('=', memberExpressionNode, rightExpression)
Nodes.getAssignmentExpressionNode('=', memberExpressionNode, propertyValue)
);
/**
* Stage 3: recursively processing nested object expressions
*/
if (NodeGuards.isObjectExpressionNode(property.value)) {
this.transformObjectExpressionNode(
property.value,
memberExpressionNode,
variableDeclarator
);
this.transformObjectExpressionNode(property.value, memberExpressionNode, variableDeclarator);
}
/**
@@ -28,7 +28,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
/**
* @type {string}
*/
private static deadCodeInjectionRootAstHostNodeName: string = 'deadCodeInjectionRootAstHostNode';
private static readonly deadCodeInjectionRootAstHostNodeName: string = 'deadCodeInjectionRootAstHostNode';
/**
* @type {number}
@@ -107,8 +107,8 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
NodeGuards.isAwaitExpressionNode(node) ||
NodeGuards.isSuperNode(node);
let nestedBlockStatementsCount: number = 0,
isValidBlockStatementNode: boolean = true;
let nestedBlockStatementsCount: number = 0;
let isValidBlockStatementNode: boolean = true;
estraverse.traverse(blockStatementNode, {
enter: (node: ESTree.Node): estraverse.VisitorOption | void => {
@@ -27,12 +27,12 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
/**
* @type {number}
*/
private static rc4KeyLength: number = 4;
private static readonly rc4KeyLength: number = 4;
/**
* @type {number}
*/
private static rc4KeysCount: number = 50;
private static readonly rc4KeysCount: number = 50;
/**
* @type {ICryptUtils}
@@ -188,8 +188,8 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
* @returns {IEncodedValue}
*/
private getEncodedValue (value: string): IEncodedValue {
let encodedValue: string,
key: string | null = null;
let encodedValue: string;
let key: string | null = null;
switch (this.options.stringArrayEncoding) {
case StringArrayEncoding.Rc4:
@@ -17,7 +17,7 @@ export class CommentsTransformer extends AbstractNodeTransformer {
/**
* @type {string[]}
*/
private static preservedWords: string[] = ['@license', '@preserve'];
private static readonly preservedWords: string[] = ['@license', '@preserve'];
/**
* @param {IRandomGenerator} randomGenerator
@@ -2,7 +2,7 @@ import { inject, injectable, } from 'inversify';
import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
import * as ESTree from 'estree';
import jsStringEscape = require('js-string-escape');
import jsStringEscape from 'js-string-escape';
import { TStatement } from '../../types/node/TStatement';
+1 -1
View File
@@ -37,7 +37,7 @@ export class Options implements IOptions {
/**
* @type {ValidatorOptions}
*/
private static validatorOptions: ValidatorOptions = {
private static readonly validatorOptions: ValidatorOptions = {
validationError: {
target: false
}
+2
View File
@@ -1 +1,3 @@
/* tslint:disable:interface-over-type-literal */
export type TObject <T = any> = {[key: string]: T};
+3 -3
View File
@@ -65,9 +65,9 @@ export class CryptUtils implements ICryptUtils {
s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
const randomMerge: (s1: string, s2: string) => string = (s1: string, s2: string): string => {
let i1: number = -1,
i2: number = -1,
result: string = '';
let i1: number = -1;
let i2: number = -1;
let result: string = '';
while (i1 < s1.length || i2 < s2.length) {
if (this.randomGenerator.getMathRandom() < 0.5 && i2 < s2.length) {
+2 -2
View File
@@ -26,8 +26,8 @@ export class EscapeSequenceEncoder implements IEscapeSequenceEncoder {
const escapeSequenceRegExp: RegExp = new RegExp('[\'\"\\\\\\s]');
const regExp: RegExp = new RegExp('[\\x00-\\x7F]');
let prefix: string,
template: string;
let prefix: string;
let template: string;
const result: string = string.replace(replaceRegExp, (character: string): string => {
if (!encodeAllSymbols && !escapeSequenceRegExp.exec(character)) {
+21 -4
View File
@@ -3,12 +3,14 @@
"tslint-eslint-rules"
],
"rules": {
"adjacent-overload-signatures": true,
"align": [
true,
"parameters",
"statements"
],
"array-bracket-spacing": [true, "never"],
"arrow-return-shorthand": true,
"ban": [
true,
[ "_", "forEach" ],
@@ -17,8 +19,10 @@
[ "angular", "forEach" ]
],
"ban-comma-operator": true,
"binary-expression-operand-order": true,
"block-spacing": [true, "always"],
"brace-style": [true, "1tbs"],
"callable-types": true,
"class-name": true,
"comment-format": [
true,
@@ -26,6 +30,7 @@
"check-lowercase"
],
"curly": true,
"cyclomatic-complexity": [true, 10],
"eofline": true,
"forin": true,
"indent": [
@@ -36,6 +41,7 @@
true,
"always-prefix"
],
"interface-over-type-literal": true,
"import-spacing": true,
"jsdoc-format": true,
"label-position": true,
@@ -45,7 +51,8 @@
true,
{ "order": "fields-first" }
],
"new-parens": false,
"new-parens": true,
"newline-per-chained-call": false,
"no-angle-bracket-type-assertion": false,
"no-any": false,
"no-arg": true,
@@ -66,8 +73,10 @@
"no-debugger": true,
"no-default-export": true,
"no-duplicate-case": true,
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": true,
"no-dynamic-delete": true,
"no-empty": false,
"no-empty-character-class": true,
"no-empty-interface": true,
@@ -77,18 +86,21 @@
"no-extra-semi": true,
"no-inferrable-types": false,
"no-inner-declarations": [true, "both"],
"no-implicit-dependencies": false,
"no-internal-module": true,
"no-invalid-regexp": true,
"no-invalid-this": true,
"no-misused-new": true,
"no-multi-spaces": [true],
"no-namespace": true,
"no-null-keyword": false,
"no-parameter-properties": true,
"no-parameter-reassignment": false,
"no-redundant-jsdoc": false,
"no-reference": true,
"no-reference-import": true,
"no-regex-spaces": true,
"no-require-imports": false,
"no-require-imports": true,
"no-shadowed-variable": true,
"no-string-literal": true,
"no-string-throw": true,
@@ -97,11 +109,14 @@
"no-trailing-whitespace": [true, "ignore-blank-lines"],
"no-unnecessary-callback-wrapper": true,
"no-unnecessary-class": [true, "allow-static-only"],
"no-unnecessary-initializer": true,
"no-unexpected-multiline": true,
"no-unsafe-finally": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-var-keyword": true,
"no-var-requires": false,
"no-var-requires": true,
"max-file-line-count": [true, 500],
"object-curly-spacing": [true, "always"],
"object-literal-sort-keys": false,
"one-line": [
@@ -112,7 +127,7 @@
"check-finally",
"check-whitespace"
],
"one-variable-per-declaration": false,
"one-variable-per-declaration": true,
"only-arrow-functions": [true, "allow-declarations"],
"ordered-imports": [
true,
@@ -123,6 +138,8 @@
}
],
"prefer-const": true,
"prefer-method-signature": true,
"prefer-readonly": true,
"prefer-template": true,
"quotemark": false,
"radix": true,
+14 -10
View File
@@ -66,9 +66,9 @@
version "8.0.53"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.53.tgz#396b35af826fa66aad472c8cb7b8d5e277f4e6d8"
"@types/node@9.4.0":
version "9.4.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.0.tgz#b85a0bcf1e1cc84eb4901b7e96966aedc6f078d1"
"@types/node@9.4.1":
version "9.4.1"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.4.1.tgz#0f636f7837e15d2d73a7f6f3ea0e322eb2a5ab65"
"@types/rimraf@2.0.2":
version "2.0.2"
@@ -1087,14 +1087,18 @@ commander@2.11.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.11.0.tgz#157152fd1e7a6c8d98a5b715cf376df928004563"
commander@2.13.0, commander@^2.12.1:
version "2.13.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
commander@2.14.0:
version "2.14.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.0.tgz#7b25325963e6aace20d3a9285b09379b0c2208b5"
commander@^2.11.0:
version "2.12.2"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.12.2.tgz#0f5946c427ed9ec0d91a46bb9def53e54650e555"
commander@^2.12.1:
version "2.13.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"
commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
@@ -1994,7 +1998,7 @@ invariant@^2.2.2:
dependencies:
loose-envify "^1.0.0"
inversify@4.10.0:
inversify@^4.10.0:
version "4.10.0"
resolved "https://registry.yarnpkg.com/inversify/-/inversify-4.10.0.tgz#06b97792e69220dd150b986cde9a445b3bcb9482"
@@ -3729,9 +3733,9 @@ tslint-language-service@0.9.8:
version "0.9.8"
resolved "https://registry.yarnpkg.com/tslint-language-service/-/tslint-language-service-0.9.8.tgz#22a6f2f926b7c0a4cafed3ae1f65021e8008dc96"
tslint-webpack-plugin@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/tslint-webpack-plugin/-/tslint-webpack-plugin-1.1.0.tgz#7b222a1115aa7da83a3f2952ba72ba8fd583ea00"
tslint-webpack-plugin@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/tslint-webpack-plugin/-/tslint-webpack-plugin-1.1.1.tgz#cd6a436395a73554530a7a2966ba57bc4f9e2d76"
dependencies:
chalk "^2.1.0"