Skip to content

Commit

Permalink
Merge pull request #9 from nanoporetech/improvement/code-refactor
Browse files Browse the repository at this point in the history
Improvement/code refactor
  • Loading branch information
glenveegee authored Feb 10, 2021
2 parents 5ca7ab6 + a231973 commit c2d0923
Show file tree
Hide file tree
Showing 15 changed files with 2,824 additions and 10,060 deletions.
48 changes: 29 additions & 19 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
// src has additional rules at src/.eslintrc.js
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
},
plugins: ['@typescript-eslint', 'prettier'],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended", // Uses the recommended rules from the @typescript-eslint/eslint-plugin
"plugin:@typescript-eslint/recommended-requiring-type-checking",
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
project: `./tsconfig.eslint.json`
env: {
browser: true,
commonjs: true,
node: true,
mocha: true,
es6: true,
},
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-return": "off",
rules: {
curly: 'error',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/naming-convention': [
'error',
{ selector: 'variable', format: ['camelCase', 'UPPER_CASE', 'PascalCase'] },
],
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/class-name-casing': 'off',
'@typescript-eslint/no-empty-function': 'off',
'prettier/prettier': 'error',
},
};
12,112 changes: 2,462 additions & 9,650 deletions package-lock.json

Large diffs are not rendered by default.

62 changes: 23 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@metrichor/jmespath",
"description": "Typescript implementation of the JMESPath spec (100% compliant)",
"version": "0.1.10",
"version": "0.2.0",
"author": {
"name": "Oxford Nanopore Technologies",
"email": "[email protected]",
Expand Down Expand Up @@ -41,60 +41,44 @@
"lint:fix": "npm run lint -- --fix",
"prebuild": "rimraf dist",
"perf": "node scripts/perf.js",
"build": "tsc --outDir dist/lib -d --module commonjs --declarationDir dist/types && rollup -c rollup.config.ts",
"build": "tsc --outDir dist/lib -d --module commonjs && rollup -c rollup.config.ts",
"start": "rollup -c rollup.config.ts -w",
"test": "jest --coverage",
"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"deploy-docs": "ts-node scripts/gh-pages-publish",
"report-coverage": "cat ./coverage/lcov.info | coveralls",
"commit": "git-cz",
"semantic-release": "semantic-release",
"semantic-release-prepare": "ts-node scripts/semantic-release-prepare",
"precommit": "lint-staged"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-typescript": "^6.0.0",
"@types/jest": "^26.0.14",
"@types/node": "^14.11.8",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@rollup/plugin-typescript": "^8.1.1",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"benchmark": "^2.1.4",
"colors": "^1.4.0",
"commitizen": "^4.2.1",
"coveralls": "^3.1.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"jest": "^26.5.2",
"jest-cli": "^26.5.2",
"jest-config": "^26.5.2",
"lint-staged": "^10.4.0",
"prettier": "^2.1.2",
"prettier-eslint": "^11.0.0",
"prompt": "^1.0.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.3.1",
"husky": "^5.0.9",
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"jest-config": "^26.6.3",
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"prettier-eslint": "^12.0.0",
"prompt": "^1.1.0",
"rimraf": "^3.0.2",
"rollup": "^2.29.0",
"rollup": "^2.38.5",
"rollup-plugin-sourcemaps": "^0.6.3",
"rollup-plugin-terser": "^7.0.2",
"semantic-release": "^17.1.2",
"shelljs": "^0.8.4",
"ts-jest": "^26.4.1",
"ts-node": "^9.0.0",
"typedoc": "^0.19.2",
"typescript": "^4.0.3"
"ts-jest": "^26.5.1",
"ts-node": "^9.1.1",
"typedoc": "^0.20.23",
"typescript": "^4.1.3"
},
"dependencies": {}
}
37 changes: 0 additions & 37 deletions scripts/semantic-release-prepare.js

This file was deleted.

16 changes: 8 additions & 8 deletions src/Lexer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isAlpha, isNum, isAlphaNum, trimLeft } from './utils';
import { JSONValue } from '.';
import { isAlpha, isNum, isAlphaNum } from './utils/index';
import type { JSONValue } from './index';

export enum Token {
TOK_EOF = 'EOF',
Expand Down Expand Up @@ -34,7 +34,7 @@ export enum Token {
TOK_LITERAL = 'Literal',
}

export type LexerTokenValue = string | number | JSONValue;
export type LexerTokenValue = JSONValue;

export interface LexerToken {
type: Token;
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface ComparitorNode extends ExpressionNode {

export type ExpressionNodeTree = ASTNode | ExpressionNode | FieldNode | ValueNode;

export const basicTokens = {
export const basicTokens: Record<string, Token> = {
'(': Token.TOK_LPAREN,
')': Token.TOK_RPAREN,
'*': Token.TOK_STAR,
Expand All @@ -81,14 +81,14 @@ export const basicTokens = {
'}': Token.TOK_RBRACE,
};

const operatorStartToken = {
const operatorStartToken: Record<string, boolean> = {
'!': true,
'<': true,
'=': true,
'>': true,
};

const skipChars = {
const skipChars: Record<string, boolean> = {
'\t': true,
'\n': true,
'\r': true,
Expand Down Expand Up @@ -116,7 +116,7 @@ class StreamLexer {
} else if (basicTokens[stream[this._current]] !== undefined) {
tokens.push({
start: this._current,
type: basicTokens[stream[this._current]] as Token,
type: basicTokens[stream[this._current]],
value: stream[this._current],
});
this._current += 1;
Expand Down Expand Up @@ -296,7 +296,7 @@ class StreamLexer {
}
this._current = current;
}
let literalString = trimLeft(stream.slice(start, this._current));
let literalString = stream.slice(start, this._current).trimLeft();
literalString = literalString.replace('\\`', '`');
const literal: JSONValue = this.looksLikeJSON(literalString)
? (JSON.parse(literalString) as JSONValue)
Expand Down
Loading

0 comments on commit c2d0923

Please sign in to comment.