Skip to content

Commit f5e9a66

Browse files
authored
[Improvements] ESLint action (#1099)
* TSLint -> ESLint, GitHub Action * Update eslint.yml * Autofix * more autofix * fix * manually fix some issues * Update CHANGELOG.md
1 parent be6f9b7 commit f5e9a66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1694
-982
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
*.d.ts
3+
src/components/tools/paragraph
4+
src/polyfills.ts

.eslintrc

Lines changed: 16 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,18 @@
11
{
2-
/** Enable ES6 features */
3-
"parserOptions": {
4-
"ecmaVersion": 2017,
5-
"sourceType": "module"
6-
},
7-
"rules": {
8-
9-
"arrow-spacing": [2, {
10-
"before": true,
11-
"after": true
12-
}],
13-
14-
/** Variables */
15-
"no-catch-shadow": 2,
16-
"no-delete-var": 2,
17-
"no-label-var": 2,
18-
"no-shadow-restricted-names": 2,
19-
"no-shadow": 2,
20-
"no-undef-init": 2,
21-
"no-undef": 2,
22-
"no-unused-vars": 0,
23-
24-
/** Style */
25-
"array-bracket-spacing": [2, "never", {
26-
"singleValue": true,
27-
"objectsInArrays": true,
28-
"arraysInArrays": true
29-
}],
30-
"quotes": [2, "single", {
31-
"avoidEscape": true,
32-
"allowTemplateLiterals": true
33-
}],
34-
"eqeqeq": 0,
35-
"brace-style": [2, "1tbs"],
36-
"comma-spacing": [2, {
37-
"before": false,
38-
"after": true
39-
}],
40-
"comma-style": [2, "last"],
41-
"eol-last": 0,
42-
"no-nested-ternary": 1,
43-
"no-trailing-spaces": 2,
44-
"no-mixed-spaces-and-tabs": 2,
45-
"padded-blocks": [2, "never"],
46-
"space-before-blocks": 1,
47-
"space-before-function-paren": [1, {
48-
"anonymous": "always",
49-
"named": "never"
50-
}],
51-
"spaced-comment": [2, "always", {
52-
"exceptions": ["-", "+"],
53-
"markers": ["=", "!"]
54-
}],
55-
"semi": [2, "always"],
56-
"indent": [2, 2, {
57-
"SwitchCase": 1
58-
}],
59-
"camelcase": [2, {
60-
"properties": "always"
61-
}],
62-
"newline-after-var": [1, "always"]
63-
64-
},
65-
"globals":{
66-
"document": true,
67-
"module": true,
68-
"require": true,
69-
"window": true,
70-
"console" : true,
71-
"codex": true,
72-
"VERSION" : true,
73-
"Promise" : true,
74-
"MutationObserver": true,
75-
"FormData": true,
76-
"XMLHttpRequest": true,
77-
"ActiveXObject": true,
78-
"RegExp": true,
79-
"Module": true,
80-
"Node": true,
81-
"Element": true,
82-
"DocumentFragment": true,
83-
"Proxy": true,
84-
"Symbol": true,
85-
"$": true,
86-
"_": true,
87-
"setTimeout": true,
88-
"process": true,
89-
"__dirname": true,
90-
"Map": true
91-
}
2+
"extends": [
3+
"codex"
4+
],
5+
"rules": {
6+
/**
7+
* Temporary suppress some errors. We need to fix them partially in next patches
8+
*/
9+
"@typescript-eslint/explicit-function-return-type": ["warn"],
10+
"@typescript-eslint/explicit-member-accessibility": ["warn"],
11+
"@typescript-eslint/member-ordering": ["warn"],
12+
"@typescript-eslint/no-empty-function": ["warn"],
13+
"no-prototype-builtins": ["warn"],
14+
"no-mixed-operators": ["warn"],
15+
"import/no-duplicates": ["warn"],
16+
"no-case-declarations": ["warn"]
17+
}
9218
}

.github/workflows/eslint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: ESLint CodeX
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
lint:
7+
name: ESlint
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
12+
- name: Cache node modules
13+
uses: actions/cache@v1
14+
with:
15+
path: node_modules
16+
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
17+
restore-keys: |
18+
${{ runner.OS }}-build-${{ env.cache-name }}-
19+
${{ runner.OS }}-build-
20+
${{ runner.OS }}-
21+
22+
- run: yarn install
23+
24+
- run: yarn lint

dist/editor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/editor.js.LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* Editor.js
2626
*
2727
* Short Description (눈_눈;)
28+
*
2829
* @version 2.0
2930
*
3031
* @licence Apache-2.0

docs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
### 2.18
4+
5+
- `Improvements` - Deprecated TSLint replaced with ESLint, old config changed to [CodeX ESLint Config](https://github.com/codex-team/eslint-config).
6+
- `Improvements` - Adjusted GitHub action for ESLint.
7+
38
### 2.17
49

510
- `Improvements` - Editor's [onchange callback](https://editorjs.io/configuration#editor-modifications-callback) now accepts an API as a parameter

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"build:win": "rimraf dist && yarn svg:win && yarn build:prod",
1717
"build:dev": "webpack --mode development --progress --display-error-details --display-entrypoints --watch",
1818
"build:prod": "webpack --mode production",
19+
"lint": "eslint src/ --ext .ts",
20+
"lint:errors": "eslint src/ --ext .ts --quiet",
21+
"lint:fix": "eslint src/ --ext .ts --fix",
1922
"svg:win": "if not exist dist md dist && yarn svg",
2023
"svg": "svg-sprite-generate -d src/assets/ -o dist/sprite.svg",
2124
"pull_tools": "git submodule update --init --recursive",
@@ -43,7 +46,8 @@
4346
"core-js": "3",
4447
"css-loader": "^3.2.1",
4548
"cssnano": "^4.1.10",
46-
"eslint": "^6.7.2",
49+
"eslint": "^6.8.0",
50+
"eslint-config-codex": "^1.3.2",
4751
"eslint-loader": "^3.0.3",
4852
"extract-text-webpack-plugin": "^3.0.2",
4953
"html-janitor": "^2.0.4",
@@ -61,7 +65,6 @@
6165
"terser-webpack-plugin": "^2.2.2",
6266
"ts-loader": "^6.2.1",
6367
"tslint": "^5.14.0",
64-
"tslint-loader": "^3.5.4",
6568
"typescript": "^3.7.3",
6669
"webpack": "^4.29.6",
6770
"webpack-cli": "^3.2.3"

src/codex.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
2-
import {EditorConfig} from '../types';
32

4-
declare const VERSION: string;
3+
import { EditorConfig } from '../types';
54

65
/**
76
* Apply polyfills
@@ -11,10 +10,13 @@ import '@babel/register';
1110
import 'components/polyfills';
1211
import Core from './components/core';
1312

13+
declare const VERSION: string;
14+
1415
/**
1516
* Editor.js
1617
*
1718
* Short Description (눈_눈;)
19+
*
1820
* @version 2.0
1921
*
2022
* @licence Apache-2.0
@@ -38,11 +40,9 @@ export default class EditorJS {
3840
}
3941

4042
/**
41-
* @constructor
42-
*
43-
* @param {EditorConfig|String|undefined} [configuration] - user configuration
43+
* @param {EditorConfig|string|undefined} [configuration] - user configuration
4444
*/
45-
public constructor(configuration?: EditorConfig|string) {
45+
constructor(configuration?: EditorConfig|string) {
4646
/**
4747
* Set default onReady function
4848
*/
@@ -63,6 +63,7 @@ export default class EditorJS {
6363
/**
6464
* We need to export isReady promise in the constructor
6565
* as it can be used before other API methods are exported
66+
*
6667
* @type {Promise<void>}
6768
*/
6869
this.isReady = editor.isReady.then(() => {

src/components/__module.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
import {EditorModules} from '../types-internal/editor-modules';
2-
import {EditorConfig} from '../../types';
3-
import {ModuleConfig} from '../types-internal/module-config';
1+
import { EditorModules } from '../types-internal/editor-modules';
2+
import { EditorConfig } from '../../types';
3+
import { ModuleConfig } from '../types-internal/module-config';
44

55
/**
66
* @abstract
77
* @class Module
88
* @classdesc All modules inherits from this class.
99
*
1010
* @typedef {Module} Module
11-
* @property {Object} config - Editor user settings
11+
* @property {object} config - Editor user settings
1212
* @property {EditorModules} Editor - List of Editor modules
1313
*/
1414
export default class Module {
15-
1615
/**
1716
* Editor modules list
17+
*
1818
* @type {EditorModules}
1919
*/
2020
protected Editor: EditorModules;
2121

2222
/**
2323
* Editor configuration object
24+
*
2425
* @type {EditorConfig}
2526
*/
2627
protected config: EditorConfig;
2728

2829
/**
29-
* @constructor
30+
* @class
3031
* @param {EditorConfig}
3132
*/
32-
constructor({config}: ModuleConfig) {
33+
constructor({ config }: ModuleConfig) {
3334
if (new.target === Module) {
3435
throw new TypeError('Constructors for abstract class Module are not allowed.');
3536
}
@@ -39,6 +40,7 @@ export default class Module {
3940

4041
/**
4142
* Editor modules setter
43+
*
4244
* @param {EditorModules} Editor
4345
*/
4446
set state(Editor: EditorModules) {

src/components/block-tunes/block-tune-delete.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
*
55
* @copyright <CodeX Team> 2018
66
*/
7-
import {API, BlockTune} from '../../../types';
7+
import { API, BlockTune } from '../../../types';
88
import $ from '../dom';
99

10+
/**
11+
*
12+
*/
1013
export default class DeleteTune implements BlockTune {
11-
1214
/**
1315
* Property that contains Editor.js API methods
16+
*
1417
* @see {docs/api.md}
1518
*/
1619
private readonly api: API;
@@ -46,7 +49,7 @@ export default class DeleteTune implements BlockTune {
4649
*
4750
* @param {{api: API}} api
4851
*/
49-
constructor({api}) {
52+
constructor({ api }) {
5053
this.api = api;
5154

5255
this.resetConfirmation = () => {
@@ -56,6 +59,7 @@ export default class DeleteTune implements BlockTune {
5659

5760
/**
5861
* Create "Delete" button and add click event listener
62+
*
5963
* @returns [Element}
6064
*/
6165
public render() {
@@ -73,10 +77,10 @@ export default class DeleteTune implements BlockTune {
7377

7478
/**
7579
* Delete block conditions passed
80+
*
7681
* @param {MouseEvent} event
7782
*/
7883
public handleClick(event: MouseEvent): void {
79-
8084
/**
8185
* if block is not waiting the confirmation, subscribe on block-settings-closing event to reset
8286
* otherwise delete block
@@ -90,9 +94,7 @@ export default class DeleteTune implements BlockTune {
9094
* then reset confirmation state
9195
*/
9296
this.api.events.on('block-settings-closed', this.resetConfirmation);
93-
9497
} else {
95-
9698
/**
9799
* Unsubscribe from block-settings closing event
98100
*/
@@ -111,10 +113,11 @@ export default class DeleteTune implements BlockTune {
111113

112114
/**
113115
* change tune state
116+
*
117+
* @param state
114118
*/
115119
private setConfirmation(state): void {
116120
this.needConfirmation = state;
117121
this.nodes.button.classList.add(this.CSS.buttonConfirm);
118122
}
119-
120123
}

0 commit comments

Comments
 (0)