fix: refactor eslint

This commit is contained in:
baizn 2020-02-10 14:27:04 +08:00 committed by Moyee
parent 9868096284
commit b23b7afc4d
11 changed files with 30 additions and 26 deletions

View File

@ -16,6 +16,13 @@ module.exports = {
'no-multi-assign': 0,
'no-continue': 0,
'@typescript-eslint/no-unused-vars': 0,
'no-underscore-dangle': 0
'no-underscore-dangle': 0,
'no-useless-constructor': 0,
'prefer-destructuring': 0,
// 后面需要去掉
'no-restricted-syntax': 0,
'prefer-spread': 0,
'@typescript-eslint/camelcase': 0,
'no-loop-func': 0
},
};

View File

@ -205,8 +205,8 @@ export default class Edge extends Item implements IEdge {
}
public destroy() {
const sourceItem: Node = this.get('source' + ITEM_NAME_SUFFIX);
const targetItem: Node = this.get('target' + ITEM_NAME_SUFFIX);
const sourceItem: Node = this.get(`source${ITEM_NAME_SUFFIX}`);
const targetItem: Node = this.get(`target${ITEM_NAME_SUFFIX}`);
if(sourceItem && !sourceItem.destroyed) {
sourceItem.removeEdge(this)
}

View File

@ -82,10 +82,10 @@ export default class ItemBase implements IItemBase {
constructor(cfg: IItemBaseConfig) {
this._cfg = Object.assign(this.defaultCfg, this.getDefaultCfg(), cfg)
const group = cfg.group
const { group } = cfg
if (group) group.set('item', this)
let id = this.get('model').id
let { id } = this.get('model')
if(!id) {
id = uniqueId(this.get('type'))
@ -94,7 +94,7 @@ export default class ItemBase implements IItemBase {
this.set('id', id)
if (group) group.set('id', id)
const stateStyles = this.get('model').stateStyles;
const { stateStyles } = this.get('model');
this.set('stateStyles', stateStyles);
this.init()

View File

@ -31,8 +31,7 @@ export default class MDSLayout extends BaseLayout {
*/
public execute() {
const self = this;
const nodes = self.nodes;
const edges = self.edges || [];
const { nodes, edges = []} = self;
const center = self.center;
if (!nodes || nodes.length === 0) {
return;

View File

@ -175,7 +175,7 @@ export default class Bundling extends Base {
public updateBundling(cfg: BundlingConfig) {
const self = this;
const data = cfg.data;
const { data } = cfg;
if (data) {
self.set('data', data);
}

View File

@ -12,12 +12,10 @@ interface MenuConfig extends IPluginBaseConfig {
}
export default class Menu extends Base {
// no-useless-constructor
constructor(cfg: MenuConfig) {
super(cfg)
}
// class-methods-use-this
public getDefaultCfgs(): MenuConfig {
return {
createDOM: true, // 是否渲染 dom

View File

@ -12,7 +12,7 @@ import { Point } from '@antv/g-math/lib/types';
import { IGroup } from '@antv/g-base/lib/interfaces';
import GraphEvent from '@antv/g-base/lib/event/graph-event';
const max = Math.max;
const { max } = Math;
const DEFAULT_MODE = 'default';
const KEYSHAPE_MODE = 'keyShape';
@ -72,8 +72,7 @@ export default class MiniMap extends Base {
private initViewport() {
const cfgs:MiniMapConfig = this._cfgs as MiniMapConfig;
const size = cfgs.size;
const graph = cfgs.graph;
const { size, graph } = cfgs;
const canvas = this.get('canvas');
const containerDOM = canvas.get('container');
@ -108,7 +107,7 @@ export default class MiniMap extends Base {
}
// 如果视口已经最大了,不需要拖拽
const style = viewport.style;
const { style } = viewport;
left = parseInt(style.left, 10);
top = parseInt(style.top, 10);
width = parseInt(style.width, 10);
@ -238,8 +237,8 @@ export default class MiniMap extends Base {
modifyCSS(viewport, {
left: correctLeft,
top: correctTop,
width: width + 'px',
height: height + 'px'
width: `${width}px`,
height: `${height}px`
});
}
@ -248,7 +247,7 @@ export default class MiniMap extends Base {
*/
private updateGraphShapes() {
// const graph: Graph = this.get('graph');
const graph = this._cfgs.graph;
const { graph } = this._cfgs;
const canvas: GCanvas = this.get('canvas');
const graphGroup = graph!.get('group');
const clonedGroup = graphGroup.clone();
@ -263,7 +262,7 @@ export default class MiniMap extends Base {
// 仅在minimap上绘制keyShape
// FIXME 如果用户自定义绘制了其他内容minimap上就无法画出
private updateKeyShapes() {
const graph = this._cfgs.graph;
const { graph } = this._cfgs;
const canvas: GCanvas = this.get('canvas');
let group: IGroup = canvas.get('children')[0];
@ -291,7 +290,7 @@ export default class MiniMap extends Base {
* Minimap rect
*/
private updateDelegateShapes() {
const graph = this._cfgs.graph;
const { graph } = this._cfgs;
const canvas: GCanvas = this.get('canvas');
const group = canvas.get('children')[0] || canvas.addGroup();
const delegateStyle = this.get('delegateStyle');

View File

@ -120,7 +120,7 @@ export const shapeBase: ShapeOptions = {
*/
getLabelStyle(cfg: ModelConfig, labelCfg: ILabelConfig, group: GGroup): LabelStyle {
const calculateStyle = this.getLabelStyleByPosition!(cfg, labelCfg, group)
const attrName = this.itemType + 'Label' // 取 nodeLabeledgeLabel 的配置项
const attrName = `${this.itemType}Label` // 取 nodeLabeledgeLabel 的配置项
const defaultStyle = (Global as any)[attrName] ? (Global as any)[attrName].style : null
const labelStyle = Object.assign({}, defaultStyle, calculateStyle, labelCfg.style)
return labelStyle

View File

@ -6,6 +6,7 @@ export const getAllNodeInGroups = (data: GraphData): GroupNodeIds => {
const groupByParentId: ObjectType<GroupConfig> = groupBy(data.groups!, 'parentId');
const result: { [key: string]: GroupConfig[] } = {};
for (const parentId in groupByParentId) {
if (!parentId) {
continue;

View File

@ -302,8 +302,7 @@ export const getAdjMatrix = (data: GraphData, directed: boolean): Matrix[] => {
if (edges) {
edges.forEach((e) => {
const source = e.source;
const target = e.target;
const { source, target } = e;
const sIndex = nodeMap[source as string];
const tIndex = nodeMap[target as string];
matrix[sIndex][tIndex] = 1;

View File

@ -79,14 +79,15 @@ export const getControlPoint = (
* @return {Array} Path
*/
export const pointsToPolygon = (points: IPoint[], z?: boolean): string => {
if (!points.length) {
const { length } = points
if (!length) {
return '';
}
let path = '';
let str = '';
for (let i = 0, length = points.length; i < length; i++) {
for (let i = 0; i < length; i++) {
const item = points[i];
if (i === 0) {
str = 'M{x} {y}';