Skip to content

Commit

Permalink
[Improvements] ESLint action (codex-team#1099)
Browse files Browse the repository at this point in the history
* TSLint -> ESLint, GitHub Action

* Update eslint.yml

* Autofix

* more autofix

* fix

* manually fix some issues

* Update CHANGELOG.md
  • Loading branch information
neSpecc authored Apr 11, 2020
1 parent be6f9b7 commit f5e9a66
Show file tree
Hide file tree
Showing 64 changed files with 1,694 additions and 982 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
*.d.ts
src/components/tools/paragraph
src/polyfills.ts
106 changes: 16 additions & 90 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,92 +1,18 @@
{
/** Enable ES6 features */
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"rules": {

"arrow-spacing": [2, {
"before": true,
"after": true
}],

/** Variables */
"no-catch-shadow": 2,
"no-delete-var": 2,
"no-label-var": 2,
"no-shadow-restricted-names": 2,
"no-shadow": 2,
"no-undef-init": 2,
"no-undef": 2,
"no-unused-vars": 0,

/** Style */
"array-bracket-spacing": [2, "never", {
"singleValue": true,
"objectsInArrays": true,
"arraysInArrays": true
}],
"quotes": [2, "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}],
"eqeqeq": 0,
"brace-style": [2, "1tbs"],
"comma-spacing": [2, {
"before": false,
"after": true
}],
"comma-style": [2, "last"],
"eol-last": 0,
"no-nested-ternary": 1,
"no-trailing-spaces": 2,
"no-mixed-spaces-and-tabs": 2,
"padded-blocks": [2, "never"],
"space-before-blocks": 1,
"space-before-function-paren": [1, {
"anonymous": "always",
"named": "never"
}],
"spaced-comment": [2, "always", {
"exceptions": ["-", "+"],
"markers": ["=", "!"]
}],
"semi": [2, "always"],
"indent": [2, 2, {
"SwitchCase": 1
}],
"camelcase": [2, {
"properties": "always"
}],
"newline-after-var": [1, "always"]

},
"globals":{
"document": true,
"module": true,
"require": true,
"window": true,
"console" : true,
"codex": true,
"VERSION" : true,
"Promise" : true,
"MutationObserver": true,
"FormData": true,
"XMLHttpRequest": true,
"ActiveXObject": true,
"RegExp": true,
"Module": true,
"Node": true,
"Element": true,
"DocumentFragment": true,
"Proxy": true,
"Symbol": true,
"$": true,
"_": true,
"setTimeout": true,
"process": true,
"__dirname": true,
"Map": true
}
"extends": [
"codex"
],
"rules": {
/**
* Temporary suppress some errors. We need to fix them partially in next patches
*/
"@typescript-eslint/explicit-function-return-type": ["warn"],
"@typescript-eslint/explicit-member-accessibility": ["warn"],
"@typescript-eslint/member-ordering": ["warn"],
"@typescript-eslint/no-empty-function": ["warn"],
"no-prototype-builtins": ["warn"],
"no-mixed-operators": ["warn"],
"import/no-duplicates": ["warn"],
"no-case-declarations": ["warn"]
}
}
24 changes: 24 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: ESLint CodeX

on: [pull_request]

jobs:
lint:
name: ESlint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Cache node modules
uses: actions/cache@v1
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.OS }}-build-${{ env.cache-name }}-
${{ runner.OS }}-build-
${{ runner.OS }}-
- run: yarn install

- run: yarn lint
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/editor.js.LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Editor.js
*
* Short Description (눈_눈;)
*
* @version 2.0
*
* @licence Apache-2.0
Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 2.18

- `Improvements` - Deprecated TSLint replaced with ESLint, old config changed to [CodeX ESLint Config](https://github.com/codex-team/eslint-config).
- `Improvements` - Adjusted GitHub action for ESLint.

### 2.17

- `Improvements` - Editor's [onchange callback](https://editorjs.io/configuration#editor-modifications-callback) now accepts an API as a parameter
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"build:win": "rimraf dist && yarn svg:win && yarn build:prod",
"build:dev": "webpack --mode development --progress --display-error-details --display-entrypoints --watch",
"build:prod": "webpack --mode production",
"lint": "eslint src/ --ext .ts",
"lint:errors": "eslint src/ --ext .ts --quiet",
"lint:fix": "eslint src/ --ext .ts --fix",
"svg:win": "if not exist dist md dist && yarn svg",
"svg": "svg-sprite-generate -d src/assets/ -o dist/sprite.svg",
"pull_tools": "git submodule update --init --recursive",
Expand Down Expand Up @@ -43,7 +46,8 @@
"core-js": "3",
"css-loader": "^3.2.1",
"cssnano": "^4.1.10",
"eslint": "^6.7.2",
"eslint": "^6.8.0",
"eslint-config-codex": "^1.3.2",
"eslint-loader": "^3.0.3",
"extract-text-webpack-plugin": "^3.0.2",
"html-janitor": "^2.0.4",
Expand All @@ -61,7 +65,6 @@
"terser-webpack-plugin": "^2.2.2",
"ts-loader": "^6.2.1",
"tslint": "^5.14.0",
"tslint-loader": "^3.5.4",
"typescript": "^3.7.3",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3"
Expand Down
13 changes: 7 additions & 6 deletions src/codex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
import {EditorConfig} from '../types';

declare const VERSION: string;
import { EditorConfig } from '../types';

/**
* Apply polyfills
Expand All @@ -11,10 +10,13 @@ import '@babel/register';
import 'components/polyfills';
import Core from './components/core';

declare const VERSION: string;

/**
* Editor.js
*
* Short Description (눈_눈;)
*
* @version 2.0
*
* @licence Apache-2.0
Expand All @@ -38,11 +40,9 @@ export default class EditorJS {
}

/**
* @constructor
*
* @param {EditorConfig|String|undefined} [configuration] - user configuration
* @param {EditorConfig|string|undefined} [configuration] - user configuration
*/
public constructor(configuration?: EditorConfig|string) {
constructor(configuration?: EditorConfig|string) {
/**
* Set default onReady function
*/
Expand All @@ -63,6 +63,7 @@ export default class EditorJS {
/**
* We need to export isReady promise in the constructor
* as it can be used before other API methods are exported
*
* @type {Promise<void>}
*/
this.isReady = editor.isReady.then(() => {
Expand Down
16 changes: 9 additions & 7 deletions src/components/__module.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import {EditorModules} from '../types-internal/editor-modules';
import {EditorConfig} from '../../types';
import {ModuleConfig} from '../types-internal/module-config';
import { EditorModules } from '../types-internal/editor-modules';
import { EditorConfig } from '../../types';
import { ModuleConfig } from '../types-internal/module-config';

/**
* @abstract
* @class Module
* @classdesc All modules inherits from this class.
*
* @typedef {Module} Module
* @property {Object} config - Editor user settings
* @property {object} config - Editor user settings
* @property {EditorModules} Editor - List of Editor modules
*/
export default class Module {

/**
* Editor modules list
*
* @type {EditorModules}
*/
protected Editor: EditorModules;

/**
* Editor configuration object
*
* @type {EditorConfig}
*/
protected config: EditorConfig;

/**
* @constructor
* @class
* @param {EditorConfig}
*/
constructor({config}: ModuleConfig) {
constructor({ config }: ModuleConfig) {
if (new.target === Module) {
throw new TypeError('Constructors for abstract class Module are not allowed.');
}
Expand All @@ -39,6 +40,7 @@ export default class Module {

/**
* Editor modules setter
*
* @param {EditorModules} Editor
*/
set state(Editor: EditorModules) {
Expand Down
17 changes: 10 additions & 7 deletions src/components/block-tunes/block-tune-delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
*
* @copyright <CodeX Team> 2018
*/
import {API, BlockTune} from '../../../types';
import { API, BlockTune } from '../../../types';
import $ from '../dom';

/**
*
*/
export default class DeleteTune implements BlockTune {

/**
* Property that contains Editor.js API methods
*
* @see {docs/api.md}
*/
private readonly api: API;
Expand Down Expand Up @@ -46,7 +49,7 @@ export default class DeleteTune implements BlockTune {
*
* @param {{api: API}} api
*/
constructor({api}) {
constructor({ api }) {
this.api = api;

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

/**
* Create "Delete" button and add click event listener
*
* @returns [Element}
*/
public render() {
Expand All @@ -73,10 +77,10 @@ export default class DeleteTune implements BlockTune {

/**
* Delete block conditions passed
*
* @param {MouseEvent} event
*/
public handleClick(event: MouseEvent): void {

/**
* if block is not waiting the confirmation, subscribe on block-settings-closing event to reset
* otherwise delete block
Expand All @@ -90,9 +94,7 @@ export default class DeleteTune implements BlockTune {
* then reset confirmation state
*/
this.api.events.on('block-settings-closed', this.resetConfirmation);

} else {

/**
* Unsubscribe from block-settings closing event
*/
Expand All @@ -111,10 +113,11 @@ export default class DeleteTune implements BlockTune {

/**
* change tune state
*
* @param state
*/
private setConfirmation(state): void {
this.needConfirmation = state;
this.nodes.button.classList.add(this.CSS.buttonConfirm);
}

}
Loading

0 comments on commit f5e9a66

Please sign in to comment.