Skip to content

Commit

Permalink
ci: add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhongxuan committed Jan 16, 2021
1 parent f48b2a8 commit 8082165
Show file tree
Hide file tree
Showing 26 changed files with 889 additions and 561 deletions.
248 changes: 248 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: [
'@typescript-eslint/eslint-plugin',
'prettier',
'import',
],
extends: [
"eslint:all",
'plugin:@typescript-eslint/all',
'prettier',
'prettier/@typescript-eslint',
],
root: true,
env: {
es6: true,
node: true,
jest: true,
},
rules: {
"array-bracket-newline": [
"error",
"consistent"
],
"array-element-newline": [
"error",
"consistent"
],
"arrow-parens": [
"error",
"as-needed"
],
"class-methods-use-this": "off",
"capitalized-comments": "off",
"comma-dangle": [
"error",
"always-multiline"
],
"dot-location": [
"error",
"property"
],
"func-names": [
"error",
"as-needed"
],
"id-length": "off",
"implicit-arrow-linebreak": "off",
"init-declarations": "off",
"max-len": [
"error",
120
],
"max-lines": "off",
"max-lines-per-function": "off",
"max-params": "off",
"max-statements": "off",
"multiline-comment-style": "off",
"multiline-ternary": [
"error",
"always-multiline"
],
"newline-per-chained-call": [
"error",
{
"ignoreChainWithDepth": 2
}
],
"no-await-in-loop": "off",
"no-bitwise": "off",
"no-confusing-arrow": "off",
"no-constant-condition": [
"error",
{
"checkLoops": false
}
],
"no-continue": "off",
"no-duplicate-imports": "off",
"no-param-reassign": "off",
"no-underscore-dangle": "off",
"import/no-duplicates": [
"error",
{
"considerQueryString": true
}
],
"no-empty": "off",
"no-implicit-coercion": "off",
"no-invalid-this": "off",
"no-mixed-operators": "off",
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxEOF": 1
}
],
"no-plusplus": [
"error",
{
"allowForLoopAfterthoughts": true
}
],
"no-process-env": "off",
"no-shadow": "off",
"no-ternary": "off",
"no-unused-expressions": "off",
"no-warning-comments": "off",
"new-cap": "off",
"one-var": [
"error",
"never"
],
"padded-blocks": [
"error",
"never"
],
"padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": [
"const",
"let",
"var"
],
"next": "*"
},
{
"blankLine": "always",
"prev": "*",
"next": [
"const",
"let",
"var"
]
},
{
"blankLine": "any",
"prev": [
"const",
"let",
"var"
],
"next": [
"const",
"let",
"var"
]
},
{
"blankLine": "always",
"prev": "*",
"next": "return"
},
{
"blankLine": "always",
"prev": "block-like",
"next": "*"
},
{
"blankLine": "always",
"prev": "*",
"next": "block-like"
}
],
"prefer-destructuring": "off",
"quote-props": [
"error",
"as-needed"
],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"object-curly-spacing": [
"error",
"always"
],
"require-atomic-updates": "off",
"require-unicode-regexp": "off",
"semi": "off",
"sort-imports": "off",
"sort-keys": "off",
"wrap-regex": "off",
"import/default": "off",

"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public"
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/generic-type-naming": "off",
"@typescript-eslint/init-declarations": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-dynamic-delete": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": [
"error",
{
"allowWithDecorator": true
}
],
"@typescript-eslint/no-invalid-this": "off",
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/no-magic-numbers": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-throw-literal": "off",
"@typescript-eslint/no-type-alias": "off",
"@typescript-eslint/no-unnecessary-condition": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_$",
"varsIgnorePattern": "^_$",
"ignoreRestSiblings": true
}
],
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/prefer-readonly-parameter-types": "off",
"@typescript-eslint/promise-function-async": "off",
"@typescript-eslint/restrict-template-expressions": [
"warn",
{
"allowNumber": true
}
],
"@typescript-eslint/semi": "error",
"@typescript-eslint/strict-boolean-expressions": "off",
"@typescript-eslint/typedef": "off",
"prettier/prettier": "error"
},
};
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 120,
"tabWidth": 4,
"arrowParens": "avoid",
"bracketSpacing": true,
"parser": "typescript"
}
21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/web-highlighter.min.js",
"browser": "dist/web-highlighter.min.js",
"scripts": {
"lint": "eslint \"src/**/*.ts\" --fix",
"test": "mocha -r ts-node/register -r tsconfig-paths/register test/**.spec.ts",
"coverage": "nyc -r lcov -e .ts -x \"test/**/*.ts\" npm run test",
"serve-example": "http-server example/static",
Expand All @@ -20,9 +21,15 @@
},
"husky": {
"hooks": {
"pre-commit": "npm run test"
"pre-commit": "lint-staged && npm run test"
}
},
"lint-staged": {
"src/**/*.ts": [
"prettier --write",
"eslint --fix"
]
},
"homepage": "https://alienzhou.github.io/web-highlighter",
"repository": {
"type": "git",
Expand All @@ -46,21 +53,29 @@
"@types/jsdom-global": "^3.0.2",
"@types/mocha": "^7.0.2",
"@types/sinon": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^4.13.0",
"@typescript-eslint/parser": "^4.13.0",
"better-opn": "^1.0.0",
"chai": "^4.2.0",
"chalk": "^2.4.2",
"clean-webpack-plugin": "^1.0.0",
"coveralls": "^3.1.0",
"css-loader": "^1.0.1",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"fs-extra": "^7.0.1",
"html-webpack-plugin": "^3.2.0",
"http-server": "^0.11.1",
"husky": "^4.2.5",
"husky": "^4.3.8",
"jsdom": "^16.2.2",
"jsdom-global": "^3.0.2",
"lint-staged": "^10.5.3",
"mocha": "^7.1.2",
"npm-run-all": "^4.1.5",
"nyc": "^15.0.1",
"prettier": "^2.2.1",
"showdown": "^1.9.0",
"sinon": "^9.0.2",
"style-loader": "^0.23.1",
Expand All @@ -69,7 +84,7 @@
"ts-node": "^8.10.1",
"tsconfig-paths": "^3.9.0",
"tscpaths": "0.0.9",
"typescript": "^3.1.6",
"typescript": "^4.1.3",
"webpack": "^4.25.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": ">=3.1.11",
Expand Down
21 changes: 12 additions & 9 deletions src/data/cache.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import EventEmitter from '@src/util/event.emitter';
import HighlightSource from '../model/source';
import {ERROR} from '../types'
import type HighlightSource from '../model/source';
import { ERROR } from '../types';

class Cache extends EventEmitter {
private _data: Map<string, HighlightSource> = new Map();

constructor() {
super();
}

get data() {
return this.getAll();
}
Expand All @@ -20,8 +16,10 @@ class Cache extends EventEmitter {
save(source: HighlightSource | HighlightSource[]): void {
if (!Array.isArray(source)) {
this._data.set(source.id, source);

return;
}

source.forEach(s => this._data.set(s.id, s));
}

Expand All @@ -35,20 +33,25 @@ class Cache extends EventEmitter {

getAll(): HighlightSource[] {
const list: HighlightSource[] = [];
for (let pair of this._data) {

for (const pair of this._data) {
list.push(pair[1]);
}

return list;
}

removeAll(): string[] {
const ids: string[] = [];
for (let pair of this._data) {

for (const pair of this._data) {
ids.push(pair[0]);
}

this._data = new Map();

return ids;
}
}

export default Cache;
export default Cache;
Loading

0 comments on commit 8082165

Please sign in to comment.