diff --git a/.eslintignore b/.eslintignore index 4c43fe6..c8f79be 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,4 @@ -*.js \ No newline at end of file +*.js +node_modules +lib +coverage \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..25181f6 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,178 @@ +{ + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": [ + "@typescript-eslint" + ], + "extends": [ + "plugin:@typescript-eslint/eslint-recommended" + ], + "env": { + "es6": true, + "node": true, + "jest": true, + "browser": true + }, + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "module", + "ecmaFeatures": { + "impliedStrict": true, + "objectLiteralDuplicateProperties": false + } + }, + "rules": { + "array-bracket-spacing": [ + "error", + "never" + ], + "camelcase": [ + "error", + { + "properties": "never" + } + ], + "comma-dangle": [ + "error", + "never" + ], + "curly": [ + "error", + "all" + ], + "eol-last": [ + "error" + ], + "indent": [ + "error", + 2, + { + "SwitchCase": 1 + } + ], + "no-tabs": "error", + "keyword-spacing": [ + "error" + ], + "no-else-return": [ + "error" + ], + "no-mixed-spaces-and-tabs": [ + "error" + ], + "no-multiple-empty-lines": [ + "error" + ], + "no-spaced-func": [ + "error" + ], + "no-trailing-spaces": [ + "error" + ], + "no-undef": [ + "error" + ], + "no-unexpected-multiline": [ + "error" + ], + "quotes": [ + "error", + "single", + { + "allowTemplateLiterals": true, + "avoidEscape": true + } + ], + "max-len": [ + 0 + ], + "semi": [ + "error" + ], + "space-before-blocks": [ + "error", + "always" + ], + "space-before-function-paren": [ + "error", + "never" + ], + "space-in-parens": [ + "error", + "never" + ], + "space-unary-ops": [ + "error", + { + "nonwords": false, + "overrides": {} + } + ], + // "valid-jsdoc": ["error"] + // ECMAScript 6 rules + "arrow-body-style": [ + "error", + "as-needed", + { + "requireReturnForObjectLiteral": false + } + ], + "arrow-parens": [ + "error", + "always" + ], + "arrow-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "no-class-assign": [ + "error" + ], + "no-const-assign": [ + "error" + ], + "no-duplicate-imports": [ + "error" + ], + "no-new-symbol": [ + "error" + ], + "no-useless-rename": [ + "error" + ], + "no-var": [ + "error" + ], + "object-shorthand": [ + "error", + "always", + { + "avoidQuotes": true, + "ignoreConstructors": false + } + ], + "prefer-arrow-callback": [ + "error", + { + "allowNamedFunctions": false, + "allowUnboundThis": true + } + ], + "prefer-const": [ + "error" + ], + "prefer-rest-params": [ + "error" + ], + "prefer-template": [ + "error" + ], + "template-curly-spacing": [ + "error", + "never" + ] + } +} \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 2382e32..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,128 +0,0 @@ -module.exports = { - 'root': true, - 'parser': '@typescript-eslint/parser', - 'plugins': [ - '@typescript-eslint' - ], - 'extends': [ - 'plugin:@typescript-eslint/eslint-recommended' - ], - 'env': { - 'es6': true, - 'node': true, - 'jest': true, - 'browser': true - }, - 'parserOptions': { - 'ecmaVersion': 2018, - 'sourceType': 'module', - 'ecmaFeatures': { - 'impliedStrict': true, - 'objectLiteralDuplicateProperties': false - } - }, - 'rules': { - 'array-bracket-spacing': ['error', 'never'], - - 'camelcase': ['error', { - 'properties': 'never' - }], - - 'comma-dangle': ['error', 'never'], - - 'curly': ['error', 'all'], - - 'eol-last': ['error'], - - 'indent': ['error', 2, { - 'SwitchCase': 1 - }], - - 'keyword-spacing': ['error'], - - 'max-len': ['error', { - 'code': 180, - 'ignoreComments': true, - 'ignoreRegExpLiterals': true - }], - - 'no-else-return': ['error'], - - 'no-mixed-spaces-and-tabs': ['error'], - - 'no-multiple-empty-lines': ['error'], - - 'no-spaced-func': ['error'], - - 'no-trailing-spaces': ['error'], - - 'no-undef': ['error'], - - 'no-unexpected-multiline': ['error'], - - 'quotes': ['error', 'single', { - 'allowTemplateLiterals': true, - 'avoidEscape': true - }], - - 'max-len': [0], - - 'semi': ['error'], - - 'space-before-blocks': ['error', 'always'], - - 'space-before-function-paren': ['error', 'never'], - - 'space-in-parens': ['error', 'never'], - - 'space-unary-ops': ['error', { - 'nonwords': false, - 'overrides': {} - }], - - // 'valid-jsdoc': ['error'] - - // ECMAScript 6 rules - - 'arrow-body-style': ['error', 'as-needed', { - 'requireReturnForObjectLiteral': false - }], - - 'arrow-parens': ['error', 'always'], - - 'arrow-spacing': ['error', { - 'after': true, - 'before': true - }], - - 'no-class-assign': ['error'], - - 'no-const-assign': ['error'], - - 'no-duplicate-imports': ['error'], - - 'no-new-symbol': ['error'], - - 'no-useless-rename': ['error'], - - 'no-var': ['error'], - - 'object-shorthand': ['error', 'always', { - 'avoidQuotes': true, - 'ignoreConstructors': false - }], - - 'prefer-arrow-callback': ['error', { - 'allowNamedFunctions': false, - 'allowUnboundThis': true - }], - - 'prefer-const': ['error'], - - 'prefer-rest-params': ['error'], - - 'prefer-template': ['error'], - - 'template-curly-spacing': ['error', 'never'] - } -}; diff --git a/.vscode/settings.json b/.vscode/settings.json index 3563ac3..50f7731 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": true, + "source.organizeImports": true }, "jest.autoEnable": false } \ No newline at end of file diff --git a/package.json b/package.json index 3910911..7a186dc 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "scripts": { "prebuild": "npm run lint", "build": "tsc", - "lint": "eslint src/**/*.ts --fix", + "lint": "eslint src/** --fix", "coverage": "npm test -- --coverage --no-cache", "typedoc": "typedoc --name \"OData v4 Filter Parser\" --excludeExternals --excludeNotExported --hideGenerator --excludeExternals --excludePrivate --out docs src", "test": "jest", diff --git a/src/builder/index.ts b/src/builder/index.ts index 7271967..3feac7a 100644 --- a/src/builder/index.ts +++ b/src/builder/index.ts @@ -1,6 +1,6 @@ -import { createRequireFromPath } from 'module'; +export * from './batch'; export * from './filter'; export * from './param'; export * from './types'; -export * from './batch'; + diff --git a/src/builder/param.ts b/src/builder/param.ts index 8294dd5..24d98b0 100644 --- a/src/builder/param.ts +++ b/src/builder/param.ts @@ -1,9 +1,8 @@ -import { ODataFilter } from './filter'; - import concat from '@newdash/newdash/concat'; -import join from '@newdash/newdash/join'; import isArray from '@newdash/newdash/isArray'; +import join from '@newdash/newdash/join'; import uniq from '@newdash/newdash/uniq'; +import { ODataFilter } from './filter'; class SearchParams { diff --git a/src/expressions.ts b/src/expressions.ts index 64183e4..a15abf9 100644 --- a/src/expressions.ts +++ b/src/expressions.ts @@ -1,9 +1,9 @@ -import Utils, { SourceArray } from './utils'; +import * as ArrayOrObject from './json'; import * as Lexer from './lexer'; +import * as NameOrIdentifier from './nameOrIdentifier'; import * as PrimitiveLiteral from './primitiveLiteral'; +import Utils, { SourceArray } from './utils'; -import * as NameOrIdentifier from './nameOrIdentifier'; -import * as ArrayOrObject from './json'; export function commonExpr(value: SourceArray, index: number): Lexer.Token { const token = PrimitiveLiteral.primitiveLiteral(value, index) || diff --git a/src/index.ts b/src/index.ts index bbeae9b..53c897e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ import { Parser } from './parser'; -export * from './parser'; +export * from './builder'; export * from './lexer'; +export * from './parser'; export * from './visitor'; -export * from './builder'; export const defaultParser = new Parser(); diff --git a/src/json.ts b/src/json.ts index 0a81a51..7231d9e 100644 --- a/src/json.ts +++ b/src/json.ts @@ -1,10 +1,9 @@ -import Utils, { SourceArray } from './utils'; +import * as Expressions from './expressions'; import * as Lexer from './lexer'; -import * as PrimitiveLiteral from './primitiveLiteral'; - import * as NameOrIdentifier from './nameOrIdentifier'; +import * as PrimitiveLiteral from './primitiveLiteral'; +import Utils, { SourceArray } from './utils'; -import * as Expressions from './expressions'; export function complexColInUri(value: SourceArray, index: number): Lexer.Token { const begin = Lexer.beginArray(value, index); diff --git a/src/nameOrIdentifier.ts b/src/nameOrIdentifier.ts index 050bb7c..f2d8b85 100644 --- a/src/nameOrIdentifier.ts +++ b/src/nameOrIdentifier.ts @@ -1,6 +1,6 @@ -import Utils, { SourceArray } from './utils'; import * as Lexer from './lexer'; import * as PrimitiveLiteral from './primitiveLiteral'; +import Utils, { SourceArray } from './utils'; export function enumeration(value: SourceArray, index: number): Lexer.Token { const type = qualifiedEnumTypeName(value, index); diff --git a/src/odataUri.ts b/src/odataUri.ts index 2baa382..e1af169 100644 --- a/src/odataUri.ts +++ b/src/odataUri.ts @@ -1,7 +1,7 @@ -import { SourceArray } from './utils'; import * as Lexer from './lexer'; import * as Query from './query'; import * as ResourcePath from './resourcePath'; +import { SourceArray } from './utils'; export function odataUri(value: SourceArray, index: number, metadataContext?: any): Lexer.Token { let resource = ResourcePath.resourcePath(value, index, metadataContext); diff --git a/src/parser.ts b/src/parser.ts index 7281fe8..c7d04c3 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -1,10 +1,10 @@ +import * as Expressions from './expressions'; +import * as ArrayOrObject from './json'; import * as Lexer from './lexer'; +import * as ODataUri from './odataUri'; import * as PrimitiveLiteral from './primitiveLiteral'; -import * as Expressions from './expressions'; import * as Query from './query'; import * as ResourcePath from './resourcePath'; -import * as ODataUri from './odataUri'; -import * as ArrayOrObject from './json'; export const parserFactory = function(fn) { return function(source, options) { diff --git a/src/primitiveLiteral.ts b/src/primitiveLiteral.ts index 3929e96..ef523a1 100644 --- a/src/primitiveLiteral.ts +++ b/src/primitiveLiteral.ts @@ -1,6 +1,6 @@ -import Utils, { SourceArray } from './utils'; import * as Lexer from './lexer'; import * as NameOrIdentifier from './nameOrIdentifier'; +import Utils, { SourceArray } from './utils'; export function nullValue(value: SourceArray, index: number): Lexer.Token { diff --git a/src/query.ts b/src/query.ts index d92cbad..3893a14 100644 --- a/src/query.ts +++ b/src/query.ts @@ -1,9 +1,9 @@ -import Utils, { SourceArray } from './utils'; +import * as Expressions from './expressions'; import * as Lexer from './lexer'; -import * as PrimitiveLiteral from './primitiveLiteral'; import * as NameOrIdentifier from './nameOrIdentifier'; +import * as PrimitiveLiteral from './primitiveLiteral'; +import Utils, { SourceArray } from './utils'; -import * as Expressions from './expressions'; export function queryOptions(value: SourceArray, index: number, metadataContext?: any): Lexer.Token { let token = queryOption(value, index, metadataContext); diff --git a/src/resourcePath.ts b/src/resourcePath.ts index ad72ee2..7c6b810 100644 --- a/src/resourcePath.ts +++ b/src/resourcePath.ts @@ -1,10 +1,9 @@ -import Utils, { SourceArray } from './utils'; +import * as Expressions from './expressions'; import * as Lexer from './lexer'; -import * as PrimitiveLiteral from './primitiveLiteral'; - import * as NameOrIdentifier from './nameOrIdentifier'; +import * as PrimitiveLiteral from './primitiveLiteral'; +import Utils, { SourceArray } from './utils'; -import * as Expressions from './expressions'; export function resourcePath(value: SourceArray, index: number, metadataContext?: any): Lexer.Token { if (value[index] === 0x2f) { index++; } diff --git a/src/visitor.ts b/src/visitor.ts index 6dab7c3..42cabf3 100644 --- a/src/visitor.ts +++ b/src/visitor.ts @@ -1,7 +1,7 @@ -import { TokenType, Token } from './lexer'; -import { isPlainObject } from '@newdash/newdash/isPlainObject'; import { forEach } from '@newdash/newdash/forEach'; import { isArray } from '@newdash/newdash/isArray'; +import { isPlainObject } from '@newdash/newdash/isPlainObject'; +import { Token, TokenType } from './lexer'; /** * AST Traverser