Skip to content

Commit

Permalink
Tuned eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
midlik committed Aug 20, 2024
1 parent 18eb7ff commit f9468a4
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 92 deletions.
75 changes: 59 additions & 16 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,79 @@ export default tsEslint.config(
plugins: {
'@stylistic': stylisticEslint,
},
rules:{
'prefer-const': 'off',
rules: {
// Relax recommended rules
'prefer-const': ['error', {
destructuring: 'all', // Allow `let` when at least one destructured element will be changed
}],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/consistent-type-definitions': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-empty-object-type': 'off',

// Additional rules - general
'eqeqeq': 'error', // Forbid using `==`, enforce `===`
'no-eval': 'error', // Forbid using `eval`
'no-new-wrappers': 'error',
'no-restricted-syntax': ['error', {
selector: 'ExportDefaultDeclaration',
message: 'Default exports are not allowed',
}],
'no-var': 'error', // Forbid using `var`
'no-throw-literal': 'error', // Forbid throwing anything that's not Error, e.g. `throw 'Blabla'`
'@typescript-eslint/prefer-namespace-keyword': 'error', // Forbid `module` keyword

// Additional rules - @stylistic
'@stylistic/indent': ['error', 4],
'@stylistic/quotes': ['error', 'single', {
'@stylistic/semi': 'error', // Enforce trailing semicolons, including after type definitions
'@stylistic/comma-dangle': ['error', 'always-multiline'], // Enforce comma after last listed item when closing ] or } is on the next line
'@stylistic/quotes': ['error', 'single', { // Enforce single quotes: 'hello'
avoidEscape: true,
allowTemplateLiterals: true,
}],
'@stylistic/semi': 'off',
'@stylistic/type-annotation-spacing': 'error',
'@stylistic/brace-style': ['error', '1tbs', {
'@stylistic/brace-style': ['error', '1tbs', { // Enforce line break after { and before }
allowSingleLine: true,
}],
'@stylistic/comma-spacing': 'error',
'@stylistic/space-infix-ops': 'error',
'@stylistic/member-delimiter-style': ['error', { // Enforce commas in interfaces and types
multiline: {
delimiter: 'comma',
requireLast: true,
},
singleline: {
delimiter: 'comma',
requireLast: false,
},
'multilineDetection': 'brackets',
}],

// Additional rules - @stylistic - spacing
'@stylistic/array-bracket-spacing': 'error', // Forbid spaces in array: [_1, 2_]
'@stylistic/arrow-spacing': 'error', // Enforce space in lambda function: x_=>_x**2
'@stylistic/block-spacing': 'error', // Enforce space in one-line block: () => {_return true;_}
'@stylistic/comma-spacing': 'error', // Enforce space after comma: [1,_2,_3]
'@stylistic/computed-property-spacing': 'error', // Forbid spaces in indexing: a[_0_]
'@stylistic/function-call-spacing': 'error', // Forbid space when calling function: f_(0)
'@stylistic/key-spacing': 'error', // Enforce space after colon in object: { a:_1, b:_2 }
'@stylistic/keyword-spacing': 'error', // Enforce space after `if`, `try`, etc.: if_(true)
'@stylistic/no-multi-spaces': 'error', // Forbid more than one space: x =__5
'@stylistic/no-trailing-spaces': 'error', // No spaces at the end of line: foo()_
'@stylistic/object-curly-spacing': ['error', 'always'], // Enforce spaces in object: {_a: 1, b: 2_}
'@stylistic/semi-spacing': 'error', // Enforce space after semicolon: for (let i = 0;_i < n;_i++)
'@stylistic/space-before-blocks': 'error', // Enforce space before block: if (true)_{}
'@stylistic/space-before-function-paren': ['error', {
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
anonymous: 'always', // function_() {}
named: 'never', // function foo_() {}
asyncArrow: 'always', // async_() {}
}],
'@stylistic/space-in-parens': 'error', // Forbid spaces in parentheses: (_1, 2_)
'@stylistic/space-infix-ops': 'error', // Enforce space around infix operators: 1_+_2
'@stylistic/spaced-comment': ['error', 'always', { // Enforce space in comment: /**_Comment_*/ //_comment
block: {
balanced: true,
},
}],
'@stylistic/func-call-spacing': ['error'],
'@stylistic/keyword-spacing': ['error'],
'@stylistic/type-annotation-spacing': 'error', // Enforce space after type annotation colon: let x:_string;
},
},
);
2 changes: 1 addition & 1 deletion src/_spec/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { setFSModule } from 'molstar/lib/commonjs/mol-util/data-source';


export const TESTING_PDBS = ['1hda', '1ad5', '176d', 'AF-Q8W3K0-F1-model_v4'] as const;
export type TestingPdb = typeof TESTING_PDBS[number]
export type TestingPdb = typeof TESTING_PDBS[number];
/** Timeout for long-running tests (in ms) */
export const LONG_TEST_TIMEOUT = 600_000;

Expand Down
4 changes: 2 additions & 2 deletions src/_spec/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('api', () => {
it('getModifiedResidue', async () => {
expect(await API.getModifiedResidue('1hda')).toEqual([] as PDBeAPIReturn<'getModifiedResidue'>);
expect(await API.getModifiedResidue('1gkt')).toEqual([
{ authChainId: 'A', compoundId: 'SUI', compoundName: '(3-AMINO-2,5-DIOXO-1-PYRROLIDINYL)ACETIC ACID', entityId: 1, labelChainId: 'A', residueNumber: 54 }
{ authChainId: 'A', compoundId: 'SUI', compoundName: '(3-AMINO-2,5-DIOXO-1-PYRROLIDINYL)ACETIC ACID', entityId: 1, labelChainId: 'A', residueNumber: 54 },
] as PDBeAPIReturn<'getModifiedResidue'>);
expect(await API.getModifiedResidue('1l7c')).toEqual([
{ authChainId: 'A', compoundId: 'MSE', compoundName: 'SELENOMETHIONINE', entityId: 1, labelChainId: 'A', residueNumber: 70 },
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('api', () => {
{ chunks: [{ endResidue: 125, startResidue: 1, chainId: 'B', authChainId: 'B', entityId: '2', segment: 1 }], family: 'RF00234', familyName: 'glmS glucosamine-6-phosphate activated ribozyme', id: 'RF00234_1', source: 'Rfam' },
],
},
SCOP: {}
SCOP: {},
} as PDBeAPIReturn<'getSiftsMappings'>);
});

Expand Down
1 change: 0 additions & 1 deletion src/_spec/expected-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { checkMissingFiles, getExpectedFiles } from '../expected-files';


const API = new PDBeAPI('file://./test_data/api');
const NO_API = new PDBeAPI('', true);


describe('expected-filenames', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/_spec/image-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { ImageGenerator } from '../image-generator';
import { TestingPdb, getTestingHeadlessPlugin } from './_utils';


PluginContext; // ensure PluginContext is imported before ImageGenerator
// Ensure PluginContext is imported before ImageGenerator:
PluginContext; // eslint-disable-line @typescript-eslint/no-unused-expressions

const TEST_TIMEOUT = 180_000; // ms

Expand Down
2 changes: 1 addition & 1 deletion src/_spec/save.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'fs';
import path from 'path';

import { loadPngToRaw } from '../image/resize';
import { makeSaveFunction, } from '../save';
import { makeSaveFunction } from '../save';
import { getTestingHeadlessPlugin, isBorderBlank, isImageBlank } from './_utils';


Expand Down
8 changes: 4 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ export class PDBeAPI {
}
}

export type PDBeAPIMethod = 'pdbeStructureQualityReportPrefix' | 'getEntityNames' | 'getEntityTypes' | 'getAssemblies' | 'getPreferredAssemblyId' | 'getModifiedResidue' | 'getSiftsMappings' | 'getExperimentalMethods' | 'getChainCoverages' | 'getChainCoverageRatios'
export type PDBeAPIReturn<key extends PDBeAPIMethod> = Awaited<ReturnType<PDBeAPI[key]>>
export type PDBeAPIMethod = 'pdbeStructureQualityReportPrefix' | 'getEntityNames' | 'getEntityTypes' | 'getAssemblies' | 'getPreferredAssemblyId' | 'getModifiedResidue' | 'getSiftsMappings' | 'getExperimentalMethods' | 'getChainCoverages' | 'getChainCoverageRatios';
export type PDBeAPIReturn<key extends PDBeAPIMethod> = Awaited<ReturnType<PDBeAPI[key]>>;


/** Represents one instance of a modified residue. */
Expand Down Expand Up @@ -346,7 +346,7 @@ export type SiftsSource = typeof SIFTS_SOURCES[number];
/** */
export interface DomainRecord {
id: string,
source: string
source: string,
family: string,
familyName: string,
chunks: DomainChunkRecord[],
Expand All @@ -366,5 +366,5 @@ interface DomainChunkRecord {
endResidue: number,
/** No idea what this was supposed to mean in the original process (probably segment number
* from the API before cutting into smaller segments by removing missing residues) */
segment: number
segment: number,
}
6 changes: 3 additions & 3 deletions src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { LogLevel } from './helpers/logging';
/** Modes of operation of PDBImages */
export const Modes = ['pdb', 'alphafold'] as const;
/** Modes of operation of PDBImages */
export type Mode = typeof Modes[number]
export type Mode = typeof Modes[number];

/** Types of images that can be generated */
export const ImageTypes = ['entry', 'assembly', 'entity', 'domain', 'ligand', 'modres', 'bfactor', 'validation', 'plddt', 'all'] as const;
/** Types of images that can be generated */
export type ImageType = typeof ImageTypes[number]
export type ImageType = typeof ImageTypes[number];

/** Types of images that can be generated for each mode */
export const ImageTypesForModes = {
Expand Down Expand Up @@ -72,7 +72,7 @@ export interface Args {
log: LogLevel,
}

export type OptionalArgs = Omit<Args, 'entry_id' | 'output_dir'>
export type OptionalArgs = Omit<Args, 'entry_id' | 'output_dir'>;

/** Default values for `Args` */
export const Defaults = {
Expand Down
6 changes: 3 additions & 3 deletions src/captions/_spec/captions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const COMMON_CONTEXT = {
'1': { description: 'HEMOGLOBIN (DEOXY) (ALPHA CHAIN)', type: 'polymer', chains: [0, 1] as any, index: 0 },
'2': { description: 'HEMOGLOBIN (DEOXY) (BETA CHAIN)', type: 'polymer', chains: [2, 3] as any, index: 1 },
'3': { description: 'PROTOPORPHYRIN IX CONTAINING FE', type: 'non-polymer', chains: [4, 5, 6, 7] as any, index: 2 },
'4': { description: 'water', type: 'water', chains: [8] as any, index: 3 }
'4': { description: 'water', type: 'water', chains: [8] as any, index: 3 },
} as EntityInfo,
entityNames: { '1': ['Hemoglobin alpha chain'], '2': ['Hemoglobin beta chain', 'blablabla'], '3': [] },
nModels: 1,
view: undefined
view: undefined,
};


Expand Down Expand Up @@ -116,7 +116,7 @@ describe('captions', () => {
it('domain', () => {
expect(Captions.forDomain({
...COMMON_CONTEXT, entityId: '2',
source: 'CATH', familyId: '1.10.490.10', familyName: 'Globin-like', totalCopies: 2, shownCopies: 1, outOfRangeCopies: 0, chainId: 'B', authChainId: 'B', view: 'front'
source: 'CATH', familyId: '1.10.490.10', familyName: 'Globin-like', totalCopies: 2, shownCopies: 1, outOfRangeCopies: 0, chainId: 'B', authChainId: 'B', view: 'front',
})).toEqual({
_entry_id: '1hda',
_extras: undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/captions/captions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TextBuilder } from './text-builder';

/** Orientation of a 3D view.
* Use `undefined` when only one view is being rendered, thus it is not necessary to specify orientation. */
export type ViewType = 'front' | 'side' | 'top' | undefined
export type ViewType = 'front' | 'side' | 'top' | undefined;


/** Data needed to save an image, related captions, and metadata. */
Expand All @@ -24,7 +24,7 @@ export interface ImageSpec {
description: string,
/** Image caption, plain-text */
clean_description: string,
/** PDB or AlphaFoldDB identifier*/
/** PDB or AlphaFoldDB identifier */
_entry_id: string,
/** View orientation */
_view: ViewType,
Expand Down Expand Up @@ -172,7 +172,7 @@ export namespace Captions {
shownCopies: number,
/** Number of domain instances in the shown chain which are completely out of the observed residue range (therefore not visible) */
outOfRangeCopies: number,
view: ViewType
view: ViewType,
}): ImageSpec {
const { entryId, source, familyId, familyName, entityId, chainId, authChainId, totalCopies, shownCopies, outOfRangeCopies, view } = context;
const name = entityName(context, entityId);
Expand Down
2 changes: 1 addition & 1 deletion src/expected-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function getExpectedFilenameStemsForPdbMode(entryId: string, types: Set<Im
if (types.has('entity')) {
const entities = await promises.entities.result();
for (const entityId in entities) {
const { type, compId } = entities[entityId];
const { type } = entities[entityId];
if (type !== 'water') {
if (view === 'front') {
result.push(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/_spec/camera.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('camera', () => {
const plugin = await getTestingPlugin();
try {
const oldSnapshot = plugin.canvas3d?.camera.getSnapshot();
adjustCamera(plugin, s => ({ ...Camera.createDefaultSnapshot(), position: Vec3.create(11, 1, 1) }));
adjustCamera(plugin, () => ({ ...Camera.createDefaultSnapshot(), position: Vec3.create(11, 1, 1) }));
const newSnapshot = plugin.canvas3d?.camera.getSnapshot();
expect(newSnapshot).not.toEqual(oldSnapshot);
} finally {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/_spec/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('helpers', () => {
label: undefined,
sets: { 'X': [123] },
},
}
},
});

expect(getModifiedResidueInfo([
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('helpers', () => {
label: undefined,
sets: { 'Z': [999] },
},
}
},
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/_spec/structure-info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('structure-info', () => {
description: 'water',
index: 3,
type: 'water',
}
},
});
});

Expand Down Expand Up @@ -65,7 +65,7 @@ describe('structure-info', () => {
expect(countChainResidues(model)).toEqual({
A: 141, B: 145, C: 141, D: 145, // proteins
E: 1, F: 1, G: 1, H: 1, // hems
I: 19, J: 8, K: 10, L: 5 // waters
I: 19, J: 8, K: 10, L: 5, // waters
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SubstructureDef } from './substructure-def';


/** Like `Partial<T>` but recursive (i.e. values themselves can be partial). */
export type PPartial<T> = T extends {} ? { [P in keyof T]?: PPartial<T[P]> } | undefined : T
export type PPartial<T> = T extends object ? { [P in keyof T]?: PPartial<T[P]> } | undefined : T;

/** Create a new object with values from `first`, optionally overridden by values from `second`, recursively.
* (I know there is `mergeDeep` in `immutable` but this implementation also gives type hints). */
Expand Down Expand Up @@ -151,7 +151,7 @@ export function safePromise<T>(asyncFunction: () => Promise<T>): SafePromise<T>
} else {
throw theReason;
}
}
},
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import util from 'util';

/** Available levels for logging */
export const LogLevels = ['ALL', 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'MARK', 'OFF'] as const;
export type LogLevel = typeof LogLevels[number]
export type LogLevel = typeof LogLevels[number];

const ROOT_DIRS = ['src', 'lib', 'build'];

Expand Down
11 changes: 9 additions & 2 deletions src/helpers/structure-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ import { getLogger } from './logging';
const logger = getLogger(module);

/** Entity type (i.e. value of _entity.type in mmCIF): polymer, non-polymer, water... */
type EntityType = ReturnType<Entities['data']['type']['value']>
type EntityType = ReturnType<Entities['data']['type']['value']>;

/** Basic info about several entities, mapped by entityId */
export type EntityInfo = { [entityId: string]: { description: string, type: EntityType, chains: ChainIndex[], index: number } }
export interface EntityInfo {
[entityId: string]: {
description: string,
type: EntityType,
chains: ChainIndex[],
index: number,
},
}

/** Return basic info about entities in the structure, mapped by entityId */
export function getEntityInfo(structure: Structure) {
Expand Down
Loading

0 comments on commit f9468a4

Please sign in to comment.