Skip to content

Commit

Permalink
Fixed Linting Issues
Browse files Browse the repository at this point in the history
Signed-off-by: Adithya Krishna <[email protected]>
  • Loading branch information
Adithya Krishna committed Aug 2, 2023
1 parent 1c27c89 commit 2fda7b1
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 61 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src --cache",
"eslint-fix": "npm run eslint -- --fix",
"lint": "eslint src --cache",
"lint:fix": "npm run eslint -- --fix",
"prepack": "npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"format:fix": "prettier --check src",
"format": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
Expand All @@ -43,6 +43,7 @@
"cheminfo-types": "^1.4.0",
"eslint": "^8.25.0",
"eslint-config-cheminfo-typescript": "^11.2.2",
"eslint-plugin-import": "^2.28.0",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"ts-jest": "^29.0.3",
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/attributeExists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ test('attributeExists', () => {
let reader = new NetCDFReader(data);
expect(reader.attributeExists('operator_name')).toBe(true);
expect(reader.attributeExists('operator_nameXX')).toBe(false);
});
});
2 changes: 1 addition & 1 deletion src/__tests__/dataVariableExists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ test('dataVariableExists', () => {
let reader = new NetCDFReader(data);
expect(reader.dataVariableExists('instrument_name')).toBe(true);
expect(reader.dataVariableExists('instrument_nameXX')).toBe(false);
});
});
2 changes: 1 addition & 1 deletion src/__tests__/getAttribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ test('getAttribute', () => {

let reader = new NetCDFReader(data);
expect(reader.getAttribute('operator_name')).toBe('SC');
});
});
2 changes: 1 addition & 1 deletion src/__tests__/getDataVariableAsString.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ test('getDataVariableAsString', () => {
expect(reader.getDataVariableAsString('instrument_name')).toBe(
'Gas Chromatograph',
);
});
});
2 changes: 1 addition & 1 deletion src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ describe('Read file', () => {
expect(variables).toHaveLength(24);
expect(reader.getDataVariable('ordinate_values')).toHaveLength(4651);
});
});
});
4 changes: 2 additions & 2 deletions src/__tests__/toString.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFileSync } from "fs";
import { readFileSync } from 'fs';

import { NetCDFReader } from '../parser';

const pathFiles = `${__dirname}/files/`;

test("toString", () => {
test('toString', () => {
const data = readFileSync(`${pathFiles}P071.CDF`);

let reader = new NetCDFReader(data);
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ describe('test type mappings', () => {
expect(str2num('double')).toBe(6);
expect(str2num('undefined')).toBe(-1);
});
});
});
6 changes: 3 additions & 3 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export function record(
const type = str2num(variable.type);
const width = variable.size ? variable.size / num2bytes(type) : 1;

// size of the data
// TODO streaming data
// size of the data
// TODO streaming data
const size = recordDimension.length;

// iterates over the data
Expand All @@ -63,4 +63,4 @@ export function record(
}

return data;
}
}
8 changes: 4 additions & 4 deletions src/header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ function dimensionsList(buffer: IOBuffer): Dimensions | [] {

if (dimList === ZERO) {
notNetcdf(
buffer.readUint32() !== ZERO,
buffer.readUint32() !== ZERO,
'wrong empty tag for list of dimensions',
);
return [];
} else {
} else {
notNetcdf(dimList !== NC_DIMENSION, 'wrong tag for list of dimensions');

// Length of dimensions
Expand Down Expand Up @@ -225,7 +225,7 @@ function variablesList(
'wrong empty tag for list of variables',
);
return [];
} else {
} else {
notNetcdf(varList !== NC_VARIABLE, 'wrong tag for list of variables');

// Length of variables
Expand Down Expand Up @@ -284,4 +284,4 @@ function variablesList(
variables,
recordStep,
};
}
}
38 changes: 19 additions & 19 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IOBuffer } from "iobuffer";
import { IOBuffer } from 'iobuffer';

import { record, nonRecord } from "./data";
import { Header, header } from "./header";
import { toString } from "./toString";
import { notNetcdf } from "./utils";
import { record, nonRecord } from './data';
import { Header, header } from './header';
import { toString } from './toString';
import { notNetcdf } from './utils';

/**
* Reads a NetCDF v3.x file
Expand All @@ -20,11 +20,11 @@ export class NetCDFReader {
buffer.setBigEndian();

// Validate that it's a NetCDF file
notNetcdf(buffer.readChars(3) !== "CDF", "should start with CDF");
notNetcdf(buffer.readChars(3) !== 'CDF', 'should start with CDF');

// Check the NetCDF format
const version = buffer.readByte();
notNetcdf(version > 2, "unknown version");
notNetcdf(version > 2, 'unknown version');

// Read the header
this.header = header(buffer, version);
Expand All @@ -36,9 +36,9 @@ export class NetCDFReader {
*/
get version() {
if (this.header.version === 1) {
return "classic format";
return 'classic format';
} else {
return "64-bit offset format";
return '64-bit offset format';
}
}

Expand Down Expand Up @@ -79,7 +79,7 @@ export class NetCDFReader {
*/
getAttribute(attributeName: string) {
const attribute = this.globalAttributes.find(
(val) => val.name === attributeName
(val) => val.name === attributeName,
);
if (attribute) return attribute.value;
return null;
Expand All @@ -92,7 +92,7 @@ export class NetCDFReader {
*/
getDataVariableAsString(variableName: string) {
const variable = this.getDataVariable(variableName);
if (variable) return variable.join("");
if (variable) return variable.join('');
return null;
}

Expand All @@ -109,7 +109,7 @@ export class NetCDFReader {
*/
getDataVariable(variableName: string | Header['variables'][number]) {
let variable;
if (typeof variableName === "string") {
if (typeof variableName === 'string') {
// search the variable
variable = this.header.variables.find((val) => {
return val.name === variableName;
Expand All @@ -119,7 +119,7 @@ export class NetCDFReader {
}

// throws if variable not found
if (variable === undefined) {
if (variable === undefined) {
throw new Error('Not a valid NetCDF v3.x file: variable not found');
}

Expand Down Expand Up @@ -152,10 +152,10 @@ export class NetCDFReader {
* @param attributeName - Name of the attribute to find
* @return boolean
*/
attributeExists(attributeName: string) {
const attribute = this.globalAttributes.find(
(val) => val.name === attributeName,
);
return attribute !== undefined;
}
attributeExists(attributeName: string) {
const attribute = this.globalAttributes.find(
(val) => val.name === attributeName,
);
return attribute !== undefined;
}
}
10 changes: 5 additions & 5 deletions src/toString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export function toString(this: NetCDFReader) {
result.push(` ${dimension.name.padEnd(30)} = size: ${dimension.size}`);
}

result.push("");
result.push("GLOBAL ATTRIBUTES");
result.push('');
result.push('GLOBAL ATTRIBUTES');
for (let attribute of this.globalAttributes) {
result.push(` ${attribute.name.padEnd(30)} = ${attribute.value}`);
}

let variables = JSON.parse(JSON.stringify(this.variables));
result.push("");
result.push("VARIABLES:");
result.push('');
result.push('VARIABLES:');
for (let variable of variables) {
variable.value = this.getDataVariable(variable);
let stringify = JSON.stringify(variable.value);
Expand All @@ -25,5 +25,5 @@ export function toString(this: NetCDFReader) {
}
result.push(` ${variable.name.padEnd(30)} = ${stringify}`);
}
return result.join("\n");
return result.join('\n');
}
2 changes: 1 addition & 1 deletion src/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"declarationMap": true
},
"exclude": ["./src/**/__tests__"]
}
}
2 changes: 1 addition & 1 deletion src/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"module": "es2020",
"outDir": "lib-esm"
}
}
}
2 changes: 1 addition & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"target": "es2020"
},
"include": ["./src/**/*"]
}
}
28 changes: 14 additions & 14 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ const types = {
* @param type - integer that represents the type
* @return - parsed value of the type
*/
export function num2str(type: number): string {
export function num2str(type: number): string {
switch (Number(type)) {
case types.BYTE:
return "byte";
return 'byte';
case types.CHAR:
return "char";
return 'char';
case types.SHORT:
return "short";
return 'short';
case types.INT:
return "int";
return 'int';
case types.FLOAT:
return "float";
return 'float';
case types.DOUBLE:
return "double";
return 'double';
default:
return "undefined";
return 'undefined';
}
}

Expand Down Expand Up @@ -64,17 +64,17 @@ export function num2bytes(type: number): number {
*/
export function str2num(type: string) {
switch (String(type)) {
case "byte":
case 'byte':
return types.BYTE;
case "char":
case 'char':
return types.CHAR;
case "short":
case 'short':
return types.SHORT;
case "int":
case 'int':
return types.INT;
case "float":
case 'float':
return types.FLOAT;
case "double":
case 'double':
return types.DOUBLE;
/* istanbul ignore next */
default:
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ export function readName(buffer: IOBuffer) {
// Apply padding
padding(buffer);
return name;
}
}

0 comments on commit 2fda7b1

Please sign in to comment.