From a8e0abb0fbbb09328121051e552c11e96659192d Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Sun, 4 Oct 2020 15:50:38 +0200 Subject: [PATCH] Converted from tslint to eslint; DEFAULT_EXT and DEFAULT_PART are constant strings --- .eslintignore | 2 - .eslintrc.yml | 175 +++++++++++++++++++++- CHANGELOG.md | 2 + README.md | 2 +- examples/.eslintrc.yml | 5 + examples/test-fs-blob-storage-read-ts.ts | 4 +- examples/test-fs-blob-storage-read.js | 4 +- examples/test-fs-blob-storage-write-ts.ts | 4 +- examples/test-fs-blob-storage-write.js | 4 +- package.json | 23 ++- src/fs-blob-storage.ts | 13 +- test/.eslintrc.yml | 5 + test/fs-blob-storage-errors.ts | 4 +- test/fs-blob-storage-exclusive-errors.ts | 4 +- test/fs-blob-storage-overwrite.ts | 11 +- test/fs-blob-storage-with-default-ext.ts | 11 +- test/fs-blob-storage-with-default-part.ts | 11 +- test/fs-blob-storage-with-empty-part.ts | 11 +- test/fs-blob-storage-with-ext.ts | 11 +- test/fs-blob-storage.ts | 11 +- tslint.yml | 22 --- 21 files changed, 252 insertions(+), 87 deletions(-) create mode 100644 examples/.eslintrc.yml create mode 100644 test/.eslintrc.yml delete mode 100644 tslint.yml diff --git a/.eslintignore b/.eslintignore index b817b13..e6a03bb 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1 @@ coverage/** -lib/** -out/** diff --git a/.eslintrc.yml b/.eslintrc.yml index 1310ac4..a24afbb 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,9 +1,172 @@ -# npm i -g eslint eslint-config-prettier eslint-plugin-import eslint-plugin-node eslint-plugin-promise - env: + es6: true node: true - -extends: prettier - +extends: + - prettier + - prettier/@typescript-eslint +ignorePatterns: + - coverage/** + - lib/** +overrides: + - files: + - "**/*.ts" + parser: "@typescript-eslint/parser" + parserOptions: + project: tsconfig.json + sourceType: module + rules: + "@typescript-eslint/adjacent-overload-signatures": error + "@typescript-eslint/array-type": + - error + - default: array-simple + "@typescript-eslint/ban-types": + - error + - types: + Object: + message: Avoid using the `Object` type. Did you mean `object`? + Function: + message: Avoid using the `Function` type. Prefer a specific function type, + like `() => void`. + Boolean: + message: Avoid using the `Boolean` type. Did you mean `boolean`? + Number: + message: Avoid using the `Number` type. Did you mean `number`? + String: + message: Avoid using the `String` type. Did you mean `string`? + Symbol: + message: Avoid using the `Symbol` type. Did you mean `symbol`? + "@typescript-eslint/consistent-type-assertions": error + "@typescript-eslint/consistent-type-definitions": error + "@typescript-eslint/dot-notation": error + "@typescript-eslint/explicit-member-accessibility": + - error + - accessibility: no-public + "@typescript-eslint/member-delimiter-style": + - off + - multiline: + delimiter: none + requireLast: true + singleline: + delimiter: semi + requireLast: false + "@typescript-eslint/member-ordering": error + "@typescript-eslint/naming-convention": error + "@typescript-eslint/no-empty-function": error + "@typescript-eslint/no-empty-interface": off + "@typescript-eslint/no-explicit-any": off + "@typescript-eslint/no-misused-new": error + "@typescript-eslint/no-namespace": off + "@typescript-eslint/no-parameter-properties": off + "@typescript-eslint/no-unused-expressions": error + "@typescript-eslint/no-use-before-define": off + "@typescript-eslint/no-var-requires": error + "@typescript-eslint/prefer-for-of": error + "@typescript-eslint/prefer-function-type": error + "@typescript-eslint/prefer-namespace-keyword": error + "@typescript-eslint/semi": + - off + - null + "@typescript-eslint/triple-slash-reference": + - error + - path: always + types: prefer-import + lib: always + "@typescript-eslint/unified-signatures": error +parser: espree parserOptions: - ecmaVersion: 2017 + ecmaVersion: 2018 + sourceType: module +plugins: + - "@typescript-eslint" + - import + - jsdoc +rules: + arrow-body-style: error + arrow-parens: + - off + - always + brace-style: + - off + - off + complexity: 0 + constructor-super: error + curly: + - error + - multi-line + eqeqeq: + - error + - smart + guard-for-in: error + id-blacklist: 0 + id-match: error + import/order: error + jsdoc/check-alignment: error + jsdoc/check-indentation: error + jsdoc/newline-after-description: error + max-classes-per-file: + - error + - 1 + no-bitwise: error + no-caller: error + no-cond-assign: 0 + no-console: + - error + - allow: + - warn + - dir + - time + - timeEnd + - timeLog + - trace + - assert + - clear + - count + - countReset + - group + - groupEnd + - table + - debug + - info + - dirxml + - error + - groupCollapsed + - Console + - profile + - profileEnd + - timeStamp + - context + no-debugger: error + no-empty: error + no-eval: error + no-fallthrough: 0 + no-invalid-this: 0 + no-irregular-whitespace: 0 + no-new-wrappers: error + no-shadow: + - error + - hoist: all + no-throw-literal: error + no-undef-init: error + no-underscore-dangle: 0 + no-unsafe-finally: error + no-unused-labels: error + no-var: error + object-shorthand: error + one-var: + - error + - never + prefer-const: error + radix: error + react/jsx-curly-spacing: off + react/jsx-equals-spacing: off + react/jsx-wrap-multilines: off + space-in-parens: + - off + - never + spaced-comment: + - error + - always + - markers: + - / + use-isnan: error + valid-typeof: 0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 5439064..0cdebf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## v3.0.0 YYYY-mm-dd +- `DEFAULT_EXT` and `DEFAULT_PART` are constant strings. - Correct typings for updates @types/node. +- Converted from tslint to eslint. ## v2.1.4 2019-10-08 diff --git a/README.md b/README.md index a4b820a..73105b5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ _Typescript:_ ```ts import FsBlobStorage from "fs-blob-storage" // or -import {FsBlobStorage} from "fs-blob-storage" +import {FsBlobStorage, DEFAULT_EXT, DEFAULT_PART} from "fs-blob-storage" ``` ### DEFAULT_EXT diff --git a/examples/.eslintrc.yml b/examples/.eslintrc.yml new file mode 100644 index 0000000..c0a5884 --- /dev/null +++ b/examples/.eslintrc.yml @@ -0,0 +1,5 @@ +extends: + - ../.eslintrc.yml +parserOptions: + project: examples/tsconfig.json + sourceType: module diff --git a/examples/test-fs-blob-storage-read-ts.ts b/examples/test-fs-blob-storage-read-ts.ts index 1c5f932..7b146a1 100755 --- a/examples/test-fs-blob-storage-read-ts.ts +++ b/examples/test-fs-blob-storage-read-ts.ts @@ -2,13 +2,13 @@ /// -import {FsBlobStorage} from "../src/fs-blob-storage" - import "stream.pipeline-shim/auto" import stream from "stream" import util from "util" +import {FsBlobStorage} from "../src/fs-blob-storage" + const pipelinePromise = util.promisify(stream.pipeline) const SPOOLDIR = process.env.SPOOLDIR || "." diff --git a/examples/test-fs-blob-storage-read.js b/examples/test-fs-blob-storage-read.js index aabd3f0..be966aa 100755 --- a/examples/test-fs-blob-storage-read.js +++ b/examples/test-fs-blob-storage-read.js @@ -1,12 +1,12 @@ #!/usr/bin/env node -const {FsBlobStorage} = require("../lib/fs-blob-storage") - require("stream.pipeline-shim/auto") const stream = require("stream") const util = require("util") +const {FsBlobStorage} = require("../lib/fs-blob-storage") + const pipelinePromise = util.promisify(stream.pipeline) const SPOOLDIR = process.env.SPOOLDIR || "." diff --git a/examples/test-fs-blob-storage-write-ts.ts b/examples/test-fs-blob-storage-write-ts.ts index 9d899ad..15334cb 100755 --- a/examples/test-fs-blob-storage-write-ts.ts +++ b/examples/test-fs-blob-storage-write-ts.ts @@ -2,13 +2,13 @@ /// -import {FsBlobStorage} from "../src/fs-blob-storage" - import "stream.pipeline-shim/auto" import stream from "stream" import util from "util" +import {FsBlobStorage} from "../src/fs-blob-storage" + const pipelinePromise = util.promisify(stream.pipeline) const SPOOLDIR = process.env.SPOOLDIR || "." diff --git a/examples/test-fs-blob-storage-write.js b/examples/test-fs-blob-storage-write.js index 96b187c..0afd5df 100755 --- a/examples/test-fs-blob-storage-write.js +++ b/examples/test-fs-blob-storage-write.js @@ -1,12 +1,12 @@ #!/usr/bin/env node -const {FsBlobStorage} = require("../lib/fs-blob-storage") - require("stream.pipeline-shim/auto") const stream = require("stream") const util = require("util") +const {FsBlobStorage} = require("../lib/fs-blob-storage") + const pipelinePromise = util.promisify(stream.pipeline) const SPOOLDIR = process.env.SPOOLDIR || "." diff --git a/package.json b/package.json index 870c46e..520a7cc 100644 --- a/package.json +++ b/package.json @@ -32,16 +32,19 @@ "@types/dirty-chai": "^2.0.2", "@types/mocha": "^5.2.7", "@types/node": "^12.12.62", + "@typescript-eslint/eslint-plugin": "^4.3.0", + "@typescript-eslint/eslint-plugin-tslint": "^4.3.0", + "@typescript-eslint/parser": "^4.3.0", "chai": "^4.2.0", "changelog-parser": "^2.8.0", "coveralls": "^3.0.6", "cross-env": "^6.0.3", "dirty-chai": "^2.0.1", - "eslint": "^6.5.1", - "eslint-config-prettier": "^6.4.0", - "eslint-plugin-import": "^2.18.2", - "eslint-plugin-node": "^10.0.0", - "eslint-plugin-promise": "^4.2.1", + "eslint": "^7.10.0", + "eslint-config-prettier": "^6.12.0", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsdoc": "^30.6.3", + "eslint-plugin-node": "^11.1.0", "make-dir": "^3.0.0", "markdownlint-cli": "^0.18.0", "mocha": "^6.2.1", @@ -53,8 +56,6 @@ "shx": "^0.3.2", "stream.pipeline-shim": "^1.1.0", "ts-node": "^8.4.1", - "tslint": "^5.20.0", - "tslint-config-prettier": "^1.18.0", "typescript": "^3.6.3" }, "scripts": { @@ -62,7 +63,13 @@ "clean": "npm run clean:compile && npm run clean:coverage", "clean:compile": "shx rm -rf lib", "clean:coverage": "shx rm -rf coverage .nyc_output", - "lint": "npm run compile && tsc --pretty -p examples && tsc --pretty -p test && eslint . && tslint -t stylish -p . && tslint -t stylish -p examples && tslint -t stylish -p test && prettier --ignore-path .gitignore --list-different '**/*.{js,json,md,ts,yml}' && markdownlint \"*.md\"", + "lint": "npm run lint:tsc:src && npm run lint:tsc:test && npm run lint:tsc:examples && npm run lint:eslint && npm run lint:prettier && npm run lint:markdownlint", + "lint:tsc:examples": "tsc --noEmit --pretty --project examples", + "lint:tsc:src": "tsc --noEmit --pretty --project .", + "lint:tsc:test": "tsc --noEmit --pretty --project test", + "lint:eslint": "eslint --ext .js,.ts .", + "lint:prettier": "prettier --ignore-path .gitignore --list-different '**/*.{js,json,md,ts,yml}'", + "lint:markdownlint": "markdownlint \"*.md\"", "postpublish": "node -e \"require(\\\"changelog-parser\\\")(\\\"CHANGELOG.md\\\").then(ch => console.log(ch.versions.filter(v => v.version === \\\"$npm_package_version\\\").map(v => \\\"v$npm_package_version\\n\\n\\\" + v.body).concat(\\\"Release v$npm_package_version\\\")[0]))\" | xargs -0 git tag v$npm_package_version -a -m && git push --tags", "prepack": "npm run compile", "prepublishOnly": "npm run test", diff --git a/src/fs-blob-storage.ts b/src/fs-blob-storage.ts index bbb89b4..5e1d05a 100644 --- a/src/fs-blob-storage.ts +++ b/src/fs-blob-storage.ts @@ -1,10 +1,11 @@ /// import fs from "fs" -import mkdir from "fs.mkdir-shim" import path from "path" import util from "util" +import mkdir from "fs.mkdir-shim" + export interface FsBlobStorageOptions { ext?: string part?: string @@ -42,10 +43,10 @@ interface FsPromises { unlink: typeof fs.unlink.__promisify__ } -export class FsBlobStorage { - static readonly DEFAULT_EXT = "" - static readonly DEFAULT_PART = ".part" +export const DEFAULT_EXT = "" +export const DEFAULT_PART = ".part" +export class FsBlobStorage { protected ext: string protected part: string protected writeFlags: string @@ -55,8 +56,8 @@ export class FsBlobStorage { protected fsPromises: FsPromises constructor(options: FsBlobStorageOptions = {}) { - this.ext = options.ext !== undefined ? options.ext : FsBlobStorage.DEFAULT_EXT - this.part = options.part !== undefined ? options.part : FsBlobStorage.DEFAULT_PART + this.ext = options.ext !== undefined ? options.ext : DEFAULT_EXT + this.part = options.part !== undefined ? options.part : DEFAULT_PART this.writeFlags = options.exclusive ? "wx" : "w" this.fs = options.fs || fs this.path = options.path || "." diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml new file mode 100644 index 0000000..fdcecc6 --- /dev/null +++ b/test/.eslintrc.yml @@ -0,0 +1,5 @@ +extends: + - ../.eslintrc.yml +parserOptions: + project: test/tsconfig.json + sourceType: module diff --git a/test/fs-blob-storage-errors.ts b/test/fs-blob-storage-errors.ts index d8b7b24..5e5b5ca 100644 --- a/test/fs-blob-storage-errors.ts +++ b/test/fs-blob-storage-errors.ts @@ -1,11 +1,11 @@ import {expect} from "chai" -import {Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - import {FsBlobStorage} from "../src/fs-blob-storage" import {mockFs} from "./lib/mock-fs" +import {Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage errors", () => { diff --git a/test/fs-blob-storage-exclusive-errors.ts b/test/fs-blob-storage-exclusive-errors.ts index 8c637ec..55c7067 100644 --- a/test/fs-blob-storage-exclusive-errors.ts +++ b/test/fs-blob-storage-exclusive-errors.ts @@ -1,11 +1,11 @@ import {expect} from "chai" -import {Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - import {FsBlobStorage} from "../src/fs-blob-storage" import {mockFs} from "./lib/mock-fs" +import {Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage errors for exclusive option", () => { diff --git a/test/fs-blob-storage-overwrite.ts b/test/fs-blob-storage-overwrite.ts index 5fb27dc..571edff 100644 --- a/test/fs-blob-storage-overwrite.ts +++ b/test/fs-blob-storage-overwrite.ts @@ -1,19 +1,20 @@ +import {WriteStream} from "fs" +import path from "path" +import {Writable} from "stream" + import chai, {expect} from "chai" import dirtyChai from "dirty-chai" chai.use(dirtyChai) -import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - -import {WriteStream} from "fs" -import path from "path" import {PromiseWritable} from "promise-writable" -import {Writable} from "stream" import FsBlobStorage from "../src/fs-blob-storage" import mockFs from "./lib/mock-fs" +import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage overwrite", () => { diff --git a/test/fs-blob-storage-with-default-ext.ts b/test/fs-blob-storage-with-default-ext.ts index ccae397..5caa5ff 100644 --- a/test/fs-blob-storage-with-default-ext.ts +++ b/test/fs-blob-storage-with-default-ext.ts @@ -1,20 +1,21 @@ +import {ReadStream, WriteStream} from "fs" +import path from "path" +import {Readable, Writable} from "stream" + import chai, {expect} from "chai" import dirtyChai from "dirty-chai" chai.use(dirtyChai) -import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - -import {ReadStream, WriteStream} from "fs" -import path from "path" import {PromiseReadable} from "promise-readable" import {PromiseWritable} from "promise-writable" -import {Readable, Writable} from "stream" import FsBlobStorage from "../src/fs-blob-storage" import mockFs from "./lib/mock-fs" +import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage with ext option", () => { diff --git a/test/fs-blob-storage-with-default-part.ts b/test/fs-blob-storage-with-default-part.ts index a105949..bc883cf 100644 --- a/test/fs-blob-storage-with-default-part.ts +++ b/test/fs-blob-storage-with-default-part.ts @@ -1,20 +1,21 @@ +import {ReadStream, WriteStream} from "fs" +import path from "path" +import {Readable, Writable} from "stream" + import chai, {expect} from "chai" import dirtyChai from "dirty-chai" chai.use(dirtyChai) -import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - -import {ReadStream, WriteStream} from "fs" -import path from "path" import {PromiseReadable} from "promise-readable" import {PromiseWritable} from "promise-writable" -import {Readable, Writable} from "stream" import FsBlobStorage from "../src/fs-blob-storage" import mockFs from "./lib/mock-fs" +import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage with part option", () => { diff --git a/test/fs-blob-storage-with-empty-part.ts b/test/fs-blob-storage-with-empty-part.ts index 1b4aef7..eb783a5 100644 --- a/test/fs-blob-storage-with-empty-part.ts +++ b/test/fs-blob-storage-with-empty-part.ts @@ -1,20 +1,21 @@ +import {ReadStream, WriteStream} from "fs" +import path from "path" +import {Readable, Writable} from "stream" + import chai, {expect} from "chai" import dirtyChai from "dirty-chai" chai.use(dirtyChai) -import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - -import {ReadStream, WriteStream} from "fs" -import path from "path" import {PromiseReadable} from "promise-readable" import {PromiseWritable} from "promise-writable" -import {Readable, Writable} from "stream" import FsBlobStorage from "../src/fs-blob-storage" import mockFs from "./lib/mock-fs" +import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage with empty part options", () => { diff --git a/test/fs-blob-storage-with-ext.ts b/test/fs-blob-storage-with-ext.ts index f9f79a8..d0fb1b5 100644 --- a/test/fs-blob-storage-with-ext.ts +++ b/test/fs-blob-storage-with-ext.ts @@ -1,20 +1,21 @@ +import {ReadStream, WriteStream} from "fs" +import path from "path" +import {Readable, Writable} from "stream" + import chai, {expect} from "chai" import dirtyChai from "dirty-chai" chai.use(dirtyChai) -import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - -import {ReadStream, WriteStream} from "fs" -import path from "path" import {PromiseReadable} from "promise-readable" import {PromiseWritable} from "promise-writable" -import {Readable, Writable} from "stream" import FsBlobStorage from "../src/fs-blob-storage" import mockFs from "./lib/mock-fs" +import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage with ext option", () => { diff --git a/test/fs-blob-storage.ts b/test/fs-blob-storage.ts index 50267e2..fd2f4dd 100644 --- a/test/fs-blob-storage.ts +++ b/test/fs-blob-storage.ts @@ -1,20 +1,21 @@ +import {ReadStream, WriteStream} from "fs" +import path from "path" +import {Readable, Writable} from "stream" + import chai, {expect} from "chai" import dirtyChai from "dirty-chai" chai.use(dirtyChai) -import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" - -import {ReadStream, WriteStream} from "fs" -import path from "path" import {PromiseReadable} from "promise-readable" import {PromiseWritable} from "promise-writable" -import {Readable, Writable} from "stream" import FsBlobStorage from "../src/fs-blob-storage" import mockFs from "./lib/mock-fs" +import {After, And, Before, Feature, Given, Scenario, Then, When} from "./lib/steps" + const STORAGEDIR = "/tmp/storage" Feature("Test FsBlobStorage without options", () => { diff --git a/tslint.yml b/tslint.yml deleted file mode 100644 index eb5af4b..0000000 --- a/tslint.yml +++ /dev/null @@ -1,22 +0,0 @@ -extends: - - tslint:recommended - - tslint-config-prettier -rules: - curly: [true, ignore-same-line] # too strict - interface-name: false # don't like hungarian notation - max-line-length: false # prettier will handle it - member-access: [true, no-public] # public is implicit - no-console: [true, log] # `console.log` is for temporary debugging only - no-unused-variable: false # no-unused-variable is deprecated. Since TypeScript 2.9. - object-literal-sort-keys: false # too problematic - typedef: # types are mandatory - - true - - call-signature - - parameter - - property-declaration - variable-name: # allow leading underscore - - true - - check-format - - allow-leading-underscore - - require-const-for-all-caps - - ban-keywords