Skip to content

Commit

Permalink
chore: upgraded eslint config
Browse files Browse the repository at this point in the history
Signed-off-by: Ilona Shishov <[email protected]>
  • Loading branch information
IlonaShishov committed Oct 23, 2023
1 parent cc9c92b commit 3c9ab42
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 183 deletions.
72 changes: 55 additions & 17 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
module.exports = {
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
rules: {
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-redeclare': 'error',
curly: 'error',
'@typescript-eslint/naming-convention': ['error', { selector: 'class', format: ['PascalCase'] }],
semi: 'error',
eqeqeq: 'error',
quotes: ['error', 'single', { avoidEscape: true }],
'no-debugger': 'error',
'no-empty': 'error',
'@typescript-eslint/no-var-requires': 'error',
'no-unsafe-finally': 'error',
'new-parens': 'error',
'no-throw-literal': 'error',
'no-restricted-imports': ['error', 'require'],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-require-imports": "error",
'@typescript-eslint/no-unused-expressions': 'error',
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"]
},
{
"selector": ["class", "interface", "enum", "enumMember"],
"format": ["PascalCase"]
},
{
"selector": ["variable", "property", "method"],
"format": ["UPPER_CASE", "camelCase"],
"leadingUnderscore": "allow"
},
{
"selector": ["typeParameter", "typeAlias"],
"format": ["PascalCase"],
}
],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/quotes": [
"error",
"single",
{
"allowTemplateLiterals": true,
"avoidEscape": true
}
],
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/no-redeclare": "error",
"curly": 'error',
"semi": 'off',
"quotes": "off",
"no-shadow": "off",
"no-redeclare": "off",
"no-duplicate-case": "error",
"eqeqeq": ["error", "always"],
'no-debugger': 'error',
'no-empty': 'error',
'no-unsafe-finally': 'error',
'new-parens': 'error',
'no-throw-literal': 'error'
},
};
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions src/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ export interface IPosition {
export interface IKeyValueEntry {
key: string;
value: IVariant;
key_position: IPosition;
value_position: IPosition;
keyPosition: IPosition;
valuePosition: IPosition;
context: string;
context_range: Range;
contextRange: Range;
}

export class KeyValueEntry implements IKeyValueEntry {
key: string;
value: IVariant;
key_position: IPosition;
value_position: IPosition;
keyPosition: IPosition;
valuePosition: IPosition;
context: string;
context_range: Range;
contextRange: Range;

constructor(k: string, pos: IPosition, v?: IVariant, v_pos?: IPosition, c?: string, c_range?: Range) {
constructor(k: string, pos: IPosition, v?: IVariant, vPos?: IPosition, c?: string, cRange?: Range) {
this.key = k;
this.key_position = pos;
this.keyPosition = pos;
this.value = v;
this.value_position = v_pos;
this.valuePosition = vPos;
this.context = c;
this.context_range = c_range;
this.contextRange = cRange;
}
}

Expand Down Expand Up @@ -99,16 +99,16 @@ export class Dependency implements IHashableDependency {
constructor(dependency: IKeyValueEntry) {
this.name = {
value: dependency.key,
position: dependency.key_position
position: dependency.keyPosition
};
this.version = {
value: dependency.value.object,
position: dependency.value_position
position: dependency.valuePosition
};
if (dependency.context && dependency.context_range) {
if (dependency.context && dependency.contextRange) {
this.context = {
value: dependency.context,
range: dependency.context_range
range: dependency.contextRange
};
}
}
Expand Down
58 changes: 26 additions & 32 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,35 @@

class Config
{
exhort_snyk_token: string;
match_manifest_versions: boolean;
provide_fullstack_action: boolean;
forbidden_licenses: Array<string>;
no_crypto: boolean;
home_dir: string;
utm_source: string;
mvn_executable: string;
npm_executable: string;
go_executable: string;
python3_executable: string;
pip3_executable: string;
python_executable: string;
pip_executable: string;
exhort_dev_mode: string;
telemetry_id: string;
exhortSnykToken: string;
matchManifestVersions: boolean;
provideFullstackAction: boolean;
utmSource: string;
mvnExecutable: string;
npmExecutable: string;
goExecutable: string;
python3Executable: string;
pip3Executable: string;
pythonExecutable: string;
pipExecutable: string;
exhortDevMode: string;
telemetryId: string;

constructor() {
// TODO: this needs to be configurable
this.exhort_snyk_token = process.env.SNYK_TOKEN || '';
this.match_manifest_versions = (process.env.MATCH_MANIFEST_VERSIONS || '') === 'true';
this.provide_fullstack_action = (process.env.PROVIDE_FULLSTACK_ACTION || '') === 'true';
this.forbidden_licenses = [];
this.no_crypto = false;
this.home_dir = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
this.utm_source = process.env.UTM_SOURCE || '';
this.mvn_executable = process.env.MVN_EXECUTABLE || 'mvn';
this.npm_executable = process.env.NPM_EXECUTABLE || 'npm';
this.go_executable = process.env.GO_EXECUTABLE || 'go';
this.go_executable = process.env.PYTHON3_EXECUTABLE || 'python3';
this.go_executable = process.env.PIP3_EXECUTABLE || 'pip3';
this.go_executable = process.env.PYTHON_EXECUTABLE || 'python';
this.go_executable = process.env.PIP_EXECUTABLE || 'pip';
this.exhort_dev_mode = process.env.EXHORT_DEV_MODE || 'false';
this.telemetry_id = process.env.TELEMETRY_ID || '';
this.exhortSnykToken = process.env.SNYK_TOKEN || '';
this.matchManifestVersions = (process.env.MATCH_MANIFEST_VERSIONS || '') === 'true';
this.provideFullstackAction = (process.env.PROVIDE_FULLSTACK_ACTION || '') === 'true';
this.utmSource = process.env.UTM_SOURCE || '';
this.mvnExecutable = process.env.MVN_EXECUTABLE || 'mvn';
this.npmExecutable = process.env.NPM_EXECUTABLE || 'npm';
this.goExecutable = process.env.GO_EXECUTABLE || 'go';
this.python3Executable = process.env.PYTHON3_EXECUTABLE || 'python3';
this.pip3Executable = process.env.PIP3_EXECUTABLE || 'pip3';
this.pythonExecutable = process.env.PYTHON_EXECUTABLE || 'python';
this.pipExecutable = process.env.PIP_EXECUTABLE || 'pip';
this.exhortDevMode = process.env.EXHORT_DEV_MODE || 'false';
this.telemetryId = process.env.TELEMETRY_ID || '';
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/consumers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* ------------------------------------------------------------------------------------------ */
'use strict';
import { IDependency } from './collector';
import { get_range } from './utils';
import { getRange } from './utils';
import { Vulnerability } from './vulnerability';
import { VulnerabilityAggregator } from './aggregators';
import { Diagnostic, CodeAction } from 'vscode-languageserver';
Expand All @@ -15,9 +15,9 @@ interface IBindingDescriptor {
}

/* Bind & return the part of `obj` as described by `desc` */
let bind_object = (obj: any, desc: IBindingDescriptor) => {
const bindObject = (obj: any, desc: IBindingDescriptor) => {
let bind = obj;
for (let elem of desc.path) {
for (const elem of desc.path) {
if (elem in bind) {
bind = bind[elem];
} else {
Expand All @@ -30,7 +30,7 @@ let bind_object = (obj: any, desc: IBindingDescriptor) => {
/* Arbitrary metadata consumer interface */
interface IConsumer {
refbinding: IBindingDescriptor;
ref: any;
ref: string;
consume(data: any): boolean;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ class DiagnosticsPipeline implements IPipeline<Vulnerability>

run(data: any): Vulnerability {
if (this.item.consume(data)) {
let vulnerability = this.item.produce();
const vulnerability = this.item.produce();
const aggVulnerability = this.vulnerabilityAggregator.aggregate(vulnerability);
if (this.vulnerabilityAggregator.isNewVulnerability) {
const aggDiagnostic = aggVulnerability.getDiagnostic();
Expand Down Expand Up @@ -145,29 +145,29 @@ class AnalysisConsumer implements IConsumer {
constructor(public config: any) { }
consume(data: any): boolean {
if (this.refbinding !== null) {
this.ref = bind_object(data, this.refbinding);
this.ref = bindObject(data, this.refbinding);
}
if (this.issuesBinding !== null) {
this.issues = bind_object(data, this.issuesBinding);
this.issues = bindObject(data, this.issuesBinding);
this.issuesCount = this.issues !== null ? this.issues.length : 0;
}
// if (this.recommendationBinding !== null) {
// this.recommendation = bind_object(data, this.recommendationBinding);
// this.recommendation = bindObject(data, this.recommendationBinding);
// }
// if (this.recommendation !== null && this.recommendationNameBinding !== null) {
// this.recommendationName = bind_object(data, this.recommendationNameBinding);
// this.recommendationName = bindObject(data, this.recommendationNameBinding);
// }
// if (this.recommendation !== null && this.recommendationVersionBinding !== null) {
// this.recommendationVersion = bind_object(data, this.recommendationVersionBinding);
// this.recommendationVersion = bindObject(data, this.recommendationVersionBinding);
// }
// if (this.remediationsBinding !== null) {
// this.remediations = bind_object(data, this.remediationsBinding);
// this.remediations = bindObject(data, this.remediationsBinding);
// }
if (this.highestVulnerabilityBinding !== null) {
this.highestVulnerability = bind_object(data, this.highestVulnerabilityBinding);
this.highestVulnerability = bindObject(data, this.highestVulnerabilityBinding);
}
if (this.highestVulnerability !== null && this.highestVulnerabilitySeverityBinding !== null) {
this.highestVulnerabilitySeverity = bind_object(data, this.highestVulnerabilitySeverityBinding);
this.highestVulnerabilitySeverity = bindObject(data, this.highestVulnerabilitySeverityBinding);
}
return this.ref !== null;
}
Expand All @@ -189,7 +189,7 @@ class SecurityEngine extends AnalysisConsumer implements DiagnosticProducer {

produce(): Vulnerability {
return new Vulnerability(
get_range(this.context),
getRange(this.context),
this.ref,
this.issuesCount,
// this.recommendation,
Expand All @@ -202,6 +202,6 @@ class SecurityEngine extends AnalysisConsumer implements DiagnosticProducer {
}
}

let codeActionsMap = new Map<string, CodeAction>();
const codeActionsMap = new Map<string, CodeAction>();

export { DiagnosticsPipeline, SecurityEngine, codeActionsMap };
10 changes: 5 additions & 5 deletions src/providers/go.mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NaiveGomodParser {
const replaceWithIndex = line.lastIndexOf(parts[1]);
const replaceEntry: IKeyValueEntry = new KeyValueEntry(replaceWith[0].trim(), { line: 0, column: 0 });
replaceEntry.value = new Variant(ValueType.String, 'v' + replaceWithVersion[0]);
replaceEntry.value_position = { line: index + 1, column: (replaceWithIndex + replaceWithVersion.index) };
replaceEntry.valuePosition = { line: index + 1, column: (replaceWithIndex + replaceWithVersion.index) };
const replaceDependency = new Dependency(replaceEntry);
const isReplaceToVersion: boolean = replaceToVersion && replaceToVersion.length > 0;
return {key: replaceTo[0].trim() + (isReplaceToVersion ? ('@v' + replaceToVersion[0]) : ''), value: replaceDependency};
Expand All @@ -51,7 +51,7 @@ class NaiveGomodParser {
}

static parseDependencies(contents:string): Array<IDependency> {
let replaceMap = new Map<string, IDependency>();
const replaceMap = new Map<string, IDependency>();
let isExcluded = false;
let goModDeps = contents.split('\n').reduce((dependencies, line, index) => {
// ignore excluded dependencies
Expand All @@ -75,7 +75,7 @@ class NaiveGomodParser {

// stash replacement dependencies for replacement
if (line.includes('=>')) {
let replaceEntry = NaiveGomodParser.getReplaceMap(line, index);
const replaceEntry = NaiveGomodParser.getReplaceMap(line, index);
if (replaceEntry) {
replaceMap.set(replaceEntry.key, replaceEntry.value);
}
Expand All @@ -90,7 +90,7 @@ class NaiveGomodParser {
if (pkgName.length > 0) {
const entry: IKeyValueEntry = new KeyValueEntry(pkgName, { line: 0, column: 0 });
entry.value = new Variant(ValueType.String, 'v' + version[0]);
entry.value_position = { line: index + 1, column: version.index };
entry.valuePosition = { line: index + 1, column: version.index };
// Push all direct and indirect modules present in go.mod (manifest)
dependencies.push(new Dependency(entry));
}
Expand Down Expand Up @@ -118,7 +118,7 @@ export class DependencyProvider implements IDependencyProvider {
}

async collect(contents: string): Promise<Array<IDependency>> {
let parser = new NaiveGomodParser(contents);
const parser = new NaiveGomodParser(contents);
return parser.parse();
}
}
4 changes: 2 additions & 2 deletions src/providers/package.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class DependencyProvider implements IDependencyProvider {
filter(c => this.classes.includes(c.key.value)).
flatMap(c => c.value.children).
map(c => {
let entry: IKeyValueEntry = new KeyValueEntry(c.key.value, {line: c.key.loc.start.line, column: c.key.loc.start.column + 1});
const entry: IKeyValueEntry = new KeyValueEntry(c.key.value, {line: c.key.loc.start.line, column: c.key.loc.start.column + 1});
entry.value = new Variant(ValueType.String, c.value.value);
entry.value_position = {line: c.value.loc.start.line, column: c.value.loc.start.column + 1};
entry.valuePosition = {line: c.value.loc.start.line, column: c.value.loc.start.column + 1};
return new Dependency(entry);
});
}
Expand Down
Loading

0 comments on commit 3c9ab42

Please sign in to comment.