Skip to content

Commit

Permalink
Migration from tslint on eslint javascript-obfuscator#2
Browse files Browse the repository at this point in the history
  • Loading branch information
sanex3339 committed Jan 31, 2020
1 parent 64b61a7 commit 7a6a359
Show file tree
Hide file tree
Showing 60 changed files with 195 additions and 419 deletions.
73 changes: 55 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,42 @@ module.exports = {
],
"rules": {
"@typescript-eslint/adjacent-overload-signatures": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/array-type": [
"error",
{
"default": "array"
}
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/ban-types": "error",
"@typescript-eslint/brace-style": [
"error",
"1tbs",
{
"allowSingleLine": true
}
],
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/consistent-type-assertions": "off",
"@typescript-eslint/comma-spacing": "error",
"@typescript-eslint/consistent-type-assertions": [
"error",
{
"assertionStyle": "angle-bracket"
}
],
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/default-param-last": "error",
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "explicit"
}
],
"@typescript-eslint/explicit-module-boundary-types": "error",
"@typescript-eslint/func-call-spacing": "error",
"@typescript-eslint/indent": [
"off",
4
Expand All @@ -51,15 +75,18 @@ module.exports = {
}
}
],
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/member-ordering": "error",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extra-parens": "off",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-magic-numbers": "off",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-param-reassign": "off",
"@typescript-eslint/no-parameter-properties": "error",
Expand All @@ -68,33 +95,41 @@ module.exports = {
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-arguments": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "error",
"@typescript-eslint/prefer-function-type": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/quotes": "off",
"@typescript-eslint/quotes": [
"error",
"single"
],
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"@typescript-eslint/semi": [
"error",
"always"
],
"@typescript-eslint/space-before-function-paren": "error",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/triple-slash-reference": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/typedef": "error",
"@typescript-eslint/unified-signatures": "error",
"arrow-body-style": "off",
"arrow-parens": [
"off",
"as-needed"
],
"camelcase": "off",
"capitalized-comments": [
"off"
],
"brace-style": "off",
"capitalized-comments": "off",
"comma-dangle": "off",
"comma-spacing": "off",
"complexity": [
"error",
{
Expand All @@ -110,17 +145,17 @@ module.exports = {
"error",
"smart"
],
"func-call-spacing": "off",
"guard-for-in": "error",
"id-blacklist": "off",
"id-match": "off",
"import/no-default-export": "error",
"import/no-deprecated": "off",
"import/no-extraneous-dependencies": "off",
"import/no-deprecated": "error",
"import/no-extraneous-dependencies": "error",
"import/no-internal-modules": "error",
"import/no-unassigned-import": "off",
"import/order": [
"off"
],
"import/order": "off",
"indent": "off",
"jsdoc/no-types": "off",
"linebreak-style": "error",
"max-classes-per-file": [
Expand Down Expand Up @@ -171,13 +206,14 @@ module.exports = {
"no-empty": "off",
"no-eval": "off",
"no-extra-bind": "error",
"no-extra-parens": "off",
"no-extra-semi": "error",
"no-fallthrough": "off",
"no-fallthrough": "error",
"no-invalid-regexp": "error",
"no-invalid-this": "off",
"no-irregular-whitespace": "error",
"no-magic-numbers": "off",
"no-multi-str": "off",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-new-wrappers": "error",
"no-null/no-null": "off",
Expand Down Expand Up @@ -228,14 +264,15 @@ module.exports = {
],
"prefer-arrow/prefer-arrow-functions": "off",
"prefer-const": "error",
"prefer-object-spread": "off",
"prefer-object-spread": "error",
"prefer-template": "error",
"quote-props": [
"error",
"as-needed"
],
"quotes": "off",
"radix": "error",
"space-before-function-paren": "error",
"space-before-function-paren": "off",
"spaced-comment": "error",
"space-in-parens": [
"error",
Expand All @@ -254,7 +291,7 @@ module.exports = {
"unicorn/prefer-starts-ends-with": "error",
"unicorn/prefer-trim-start-end": "error",
"use-isnan": "error",
"valid-typeof": "off",
"valid-typeof": "error",
"yoda": "error"
}
};
8 changes: 4 additions & 4 deletions dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/ASTParserFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ASTParserFacade {
}
}

throw new Error(`Acorn parsing error`);
throw new Error('Acorn parsing error');
}

/**
Expand All @@ -73,11 +73,9 @@ export class ASTParserFacade {
sourceType
};

const program: ESTree.Program = (
<any>acorn
.Parser.extend(acornImportMeta)
.parse(sourceCode, config)
);
const program: ESTree.Program = <any>acorn
.Parser.extend(acornImportMeta)
.parse(sourceCode, config);

if (comments.length) {
program.comments = comments;
Expand Down
2 changes: 1 addition & 1 deletion src/JavaScriptObfuscatorFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JavaScriptObfuscatorFacade {
/**
* @type {string | undefined}
*/
public static version: string = process.env.VERSION || 'unknown';
public static version: string = process.env.VERSION ?? 'unknown';

/**
* @param {string} sourceCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class FunctionExpressionCalleeDataExtractor extends AbstractCalleeDataExt

return {
callee: calleeBlockStatement,
name: callee.name || null
name: callee.name ?? null
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class PrevailingKindOfVariablesAnalyzer implements IPrevailingKindOfVaria
});

this.prevailingKindOfVariables = this.arrayUtils.findMostOccurringElement(variableKinds)
|| PrevailingKindOfVariablesAnalyzer.defaultKindOfVariables;
?? PrevailingKindOfVariablesAnalyzer.defaultKindOfVariables;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/analyzers/scope-analyzer/ScopeAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ScopeAnalyzer implements IScopeAnalyzer {
}
}

throw new Error(`Scope analyzing error`);
throw new Error('Scope analyzing error');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/cli/JavaScriptObfuscatorCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
): void {
const outputSourceMapPath: string = CLIUtils.getOutputSourceMapPath(
outputCodePath,
options.sourceMapFileName || ''
options.sourceMapFileName ?? ''
);

options = {
Expand Down Expand Up @@ -189,7 +189,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
this.commands
.usage('<inputPath> [options]')
.version(
process.env.VERSION || 'unknown',
process.env.VERSION ?? 'unknown',
'-v, --version'
)
.option(
Expand Down Expand Up @@ -416,7 +416,7 @@ export class JavaScriptObfuscatorCLI implements IInitializable {

if (sourceCodeIndex !== null) {
const baseIdentifiersPrefix: string = this.inputCLIOptions.identifiersPrefix
|| JavaScriptObfuscatorCLI.baseIdentifiersPrefix;
?? JavaScriptObfuscatorCLI.baseIdentifiersPrefix;
const identifiersPrefix: string = `${baseIdentifiersPrefix}${sourceCodeIndex}`;

options = {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/sanitizers/ArraySanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
*/
export const ArraySanitizer: TCLISanitizer <string[]> = (value: string): string[] => {
if (value.endsWith(',')) {
throw new SyntaxError(`Multiple <list> values should be wrapped inside quotes: --option-name 'value1','value2'`);
throw new SyntaxError('Multiple <list> values should be wrapped inside quotes: --option-name \'value1\',\'value2\'');
}

return value.split(',').map((string: string) => string.trim());
Expand Down
8 changes: 4 additions & 4 deletions src/container/InversifyContainerFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
serviceIdentifier: interfaces.ServiceIdentifier<U>
): (context: interfaces.Context) => (bindingName: T) => U {
return (context: interfaces.Context): (bindingName: T) => U => {
return (bindingName: T) => {
return (bindingName: T): U => {
return context.container.getNamed<U>(serviceIdentifier, bindingName);
};
};
Expand All @@ -65,7 +65,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
return (context: interfaces.Context): (bindingName: T) => U => {
const cache: Map <T, U> = new Map();

return (bindingName: T) => {
return (bindingName: T): U => {
if (cache.has(bindingName)) {
return <U>cache.get(bindingName);
}
Expand All @@ -92,7 +92,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
const cache: Map<T, interfaces.Newable<U>> = new Map();
const cachedDependencies: Record<string, any>[] = [];

return (bindingName: T) => {
return (bindingName: T): U => {
dependencies.forEach((
dependency: interfaces.ServiceIdentifier<interfaces.Newable<Record<string, any>>>,
index: number
Expand Down Expand Up @@ -174,7 +174,7 @@ export class InversifyContainerFacade implements IInversifyContainerFacade {
this.container
.bind<IObfuscatedCode>(ServiceIdentifiers.Factory__IObfuscatedCode)
.toFactory<IObfuscatedCode>((context: interfaces.Context) => {
return (obfuscatedCodeAsString: string, sourceMapAsString: string) => {
return (obfuscatedCodeAsString: string, sourceMapAsString: string): IObfuscatedCode => {
const obfuscatedCode: IObfuscatedCode = context.container
.get<IObfuscatedCode>(ServiceIdentifiers.IObfuscatedCode);

Expand Down
2 changes: 1 addition & 1 deletion src/container/modules/custom-nodes/CustomNodesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
import { ICustomNodeFormatter } from '../../../interfaces/custom-nodes/ICustomNodeFormatter';
import { ICustomNodeGroup } from '../../../interfaces/custom-nodes/ICustomNodeGroup';

import { ControlFlowCustomNode } from "../../../enums/custom-nodes/ControlFlowCustomNode";
import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
import { CustomNode } from '../../../enums/custom-nodes/CustomNode';
import { CustomNodeGroup } from '../../../enums/custom-nodes/CustomNodeGroup';
import { DeadCodeInjectionCustomNode } from '../../../enums/custom-nodes/DeadCodeInjectionCustomNode';
Expand Down
2 changes: 1 addition & 1 deletion src/container/modules/generators/GeneratorsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const generatorsModule: interfaces.ContainerModule = new ContainerModule(
function identifierNameGeneratorFactory (): (context: interfaces.Context) => (options: IOptions) => IIdentifierNamesGenerator {
let cachedIdentifierNamesGenerator: IIdentifierNamesGenerator | null = null;

return (context: interfaces.Context): (options: IOptions) => IIdentifierNamesGenerator => (options: IOptions) => {
return (context: interfaces.Context): (options: IOptions) => IIdentifierNamesGenerator => (options: IOptions): IIdentifierNamesGenerator => {
if (cachedIdentifierNamesGenerator) {
return cachedIdentifierNamesGenerator;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { MetadataTransformer } from '../../../node-transformers/preparing-transf
import { ObfuscatingGuardsTransformer } from '../../../node-transformers/preparing-transformers/ObfuscatingGuardsTransformer';
import { ParentificationTransformer } from '../../../node-transformers/preparing-transformers/ParentificationTransformer';
import { ReservedStringObfuscatingGuard } from '../../../node-transformers/preparing-transformers/obfuscating-guards/ReservedStringObfuscatingGuard';
import { VariablePreserveTransformer } from "../../../node-transformers/preparing-transformers/VariablePreserveTransformer";
import { VariablePreserveTransformer } from '../../../node-transformers/preparing-transformers/VariablePreserveTransformer';

export const preparingTransformersModule: interfaces.ContainerModule = new ContainerModule((bind: interfaces.Bind) => {
// preparing transformers
Expand Down
2 changes: 1 addition & 1 deletion src/container/modules/storages/StoragesModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const storagesModule: interfaces.ContainerModule = new ContainerModule((b
// controlFlowStorage factory
bind<TControlFlowStorage>(ServiceIdentifiers.Factory__TControlFlowStorage)
.toFactory<TControlFlowStorage>((context: interfaces.Context) => {
return () => {
return (): TControlFlowStorage => {
const constructor: interfaces.Newable<TControlFlowStorage> = context.container
.get<interfaces.Newable<TControlFlowStorage>>(ServiceIdentifiers.Newable__TControlFlowStorage);
const randomGenerator: IRandomGenerator = context.container
Expand Down
20 changes: 10 additions & 10 deletions src/custom-nodes/AbstractCustomNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ export abstract class AbstractCustomNode <
this.options = options;
}

/**
* @param {TInitialData} args
*/
public abstract initialize (...args: TInitialData): void;

/**
* @returns {TStatement[]}
*/
Expand All @@ -98,15 +93,20 @@ export abstract class AbstractCustomNode <
.pickone(AbstractCustomNode.globalVariableTemplateFunctions);
}

/**
* @returns {TStatement[]}
*/
protected abstract getNodeStructure (nodeTemplate: string): TStatement[];

/**
* @returns {string}
*/
protected getNodeTemplate (): string {
return '';
}

/**
* @param {TInitialData} args
*/
public abstract initialize (...args: TInitialData): void;

/**
* @returns {TStatement[]}
*/
protected abstract getNodeStructure (nodeTemplate: string): TStatement[];
}
Loading

0 comments on commit 7a6a359

Please sign in to comment.