introduce ESLint (#174)

* add eslint, remove deprecated tslint

* fix lint errors
This commit is contained in:
James Garbutt
2021-05-18 01:49:56 +01:00
committed by GitHub
parent af319f7606
commit 3fe6436cc2
11 changed files with 1114 additions and 276 deletions
+23
View File
@@ -0,0 +1,23 @@
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": ["@typescript-eslint"],
"rules": {
"arrow-parens": ["error", "always"],
"prefer-const": "error",
"no-eval": "error",
"no-trailing-spaces": "error",
"no-var": "error",
"quotes": ["error", "single", {"allowTemplateLiterals": true}],
"semi": "error",
"comma-dangle": ["error", "always-multiline"],
"eqeqeq": "error",
"no-useless-escape": "off",
"@typescript-eslint/indent": ["error", 2],
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unused-vars": "off"
}
}
+1036 -169
View File
File diff suppressed because it is too large Load Diff
+4 -2
View File
@@ -8,7 +8,7 @@
"types": "bin/rough.d.ts",
"scripts": {
"build": "rm -rf bin && tsc && rollup -c",
"lint": "tslint -p tsconfig.json",
"lint": "eslint --ext ts src",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
@@ -32,10 +32,12 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"eslint": "^7.20.0",
"rollup": "^2.47.0",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.2.0",
"tslint": "^5.20.1",
"typescript": "^4.2.4"
},
"dependencies": {
+4 -2
View File
@@ -13,7 +13,7 @@ export class RoughCanvas {
this.gen = new RoughGenerator(config);
}
draw(drawable: Drawable) {
draw(drawable: Drawable): void {
const sets = drawable.sets || [];
const o = drawable.options || this.getDefaultOptions();
const ctx = this.ctx;
@@ -33,12 +33,14 @@ export class RoughCanvas {
ctx.restore();
break;
case 'fillPath':
{
ctx.save();
ctx.fillStyle = o.fill || '';
const fillRule: CanvasFillRule = (drawable.shape === 'curve' || drawable.shape === 'polygon') ? 'evenodd' : 'nonzero';
this._drawToContext(ctx, drawing, fillRule);
ctx.restore();
break;
}
case 'fillSketch':
this.fillSketch(ctx, drawing, o);
break;
@@ -148,4 +150,4 @@ export class RoughCanvas {
this.draw(drawing);
return drawing;
}
}
}
+2 -2
View File
@@ -74,7 +74,7 @@ export class HachureFiller implements PatternFiller {
if (d0 > error && d1 > error) {
intersections.push({
point: ip,
distance: d0
distance: d0,
});
}
}
@@ -110,4 +110,4 @@ export class HachureFiller implements PatternFiller {
return [];
}
}
}
}
+3 -3
View File
@@ -51,7 +51,7 @@ function straightHachureLines(points: Point[], o: ResolvedOptions): Line[] {
ymin,
ymax: Math.max(p1[1], p2[1]),
x: ymin === p1[1] ? p1[0] : p2[0],
islope: (p2[0] - p1[0]) / (p2[1] - p1[1])
islope: (p2[0] - p1[0]) / (p2[1] - p1[1]),
});
}
}
@@ -118,7 +118,7 @@ function straightHachureLines(points: Point[], o: ResolvedOptions): Line[] {
const ne = activeEdges[nexti].edge;
lines.push([
[Math.round(ce.x), y],
[Math.round(ne.x), y]
[Math.round(ne.x), y],
]);
}
}
@@ -130,4 +130,4 @@ function straightHachureLines(points: Point[], o: ResolvedOptions): Line[] {
}
}
return lines;
}
}
+5 -5
View File
@@ -31,7 +31,7 @@ export class RoughGenerator {
combineNestedSvgPaths: false,
disableMultiStroke: false,
disableMultiStrokeFill: false,
preserveVertices: false
preserveVertices: false,
};
constructor(config?: Config) {
@@ -239,7 +239,7 @@ export class RoughGenerator {
d: this.opsToPath(drawing),
stroke: o.stroke,
strokeWidth: o.strokeWidth,
fill: NOS
fill: NOS,
};
break;
case 'fillPath':
@@ -247,7 +247,7 @@ export class RoughGenerator {
d: this.opsToPath(drawing),
stroke: NOS,
strokeWidth: 0,
fill: o.fill || NOS
fill: o.fill || NOS,
};
break;
case 'fillSketch':
@@ -270,7 +270,7 @@ export class RoughGenerator {
d: this.opsToPath(drawing),
stroke: o.fill || NOS,
strokeWidth: fweight,
fill: NOS
fill: NOS,
};
}
}
}
+2 -2
View File
@@ -92,7 +92,7 @@ function orientation(p: Point, q: Point, r: Point) {
}
// Check is p1q1 intersects with p2q2
export function doIntersect(p1: Point, q1: Point, p2: Point, q2: Point) {
export function doIntersect(p1: Point, q1: Point, p2: Point, q2: Point): boolean {
const o1 = orientation(p1, q1, p2);
const o2 = orientation(p1, q1, q2);
const o3 = orientation(p2, q2, p1);
@@ -123,4 +123,4 @@ export function doIntersect(p1: Point, q1: Point, p2: Point, q2: Point) {
}
return false;
}
}
+33 -28
View File
@@ -15,7 +15,7 @@ const helper: RenderHelper = {
randOffset,
randOffsetWithRange,
ellipse,
doubleLineOps: doubleLineFillOps
doubleLineOps: doubleLineFillOps,
};
export function line(x1: number, y1: number, x2: number, y2: number, o: ResolvedOptions): OpSet {
@@ -48,7 +48,7 @@ export function rectangle(x: number, y: number, width: number, height: number, o
[x, y],
[x + width, y],
[x + width, y + height],
[x, y + height]
[x, y + height],
];
return polygon(points, o);
}
@@ -94,7 +94,7 @@ export function ellipseWithParams(x: number, y: number, o: ResolvedOptions, elli
}
return {
estimatedPoints: cp1,
opset: { type: 'path', ops: o1 }
opset: { type: 'path', ops: o1 },
};
}
@@ -299,39 +299,41 @@ function _line(x1: number, y1: number, x2: number, y2: number, o: ResolvedOption
ops.push({
op: 'move', data: [
x1 + (preserveVertices ? 0 : randomHalf()),
y1 + (preserveVertices ? 0 : randomHalf())
]
y1 + (preserveVertices ? 0 : randomHalf()),
],
});
} else {
ops.push({
op: 'move', data: [
x1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain)),
y1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain))
]
y1 + (preserveVertices ? 0 : _offsetOpt(offset, o, roughnessGain)),
],
});
}
}
if (overlay) {
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
midDispX + x1 + (x2 - x1) * divergePoint + randomHalf(),
midDispY + y1 + (y2 - y1) * divergePoint + randomHalf(),
midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomHalf(),
midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomHalf(),
x2 + (preserveVertices ? 0 : randomHalf()),
y2 + (preserveVertices ? 0 : randomHalf())
]
y2 + (preserveVertices ? 0 : randomHalf()),
],
});
} else {
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
midDispX + x1 + (x2 - x1) * divergePoint + randomFull(),
midDispY + y1 + (y2 - y1) * divergePoint + randomFull(),
midDispX + x1 + 2 * (x2 - x1) * divergePoint + randomFull(),
midDispY + y1 + 2 * (y2 - y1) * divergePoint + randomFull(),
x2 + (preserveVertices ? 0 : randomFull()),
y2 + (preserveVertices ? 0 : randomFull())
]
y2 + (preserveVertices ? 0 : randomFull()),
],
});
}
return ops;
@@ -384,10 +386,12 @@ function _curve(points: Point[], closePoint: Point | null, o: ResolvedOptions):
} else if (len === 3) {
ops.push({ op: 'move', data: [points[1][0], points[1][1]] });
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
points[1][0], points[1][1],
points[2][0], points[2][1],
points[2][0], points[2][1]]
points[2][0], points[2][1],
],
});
} else if (len === 2) {
ops.push(..._doubleLine(points[0][0], points[0][1], points[1][0], points[1][1], o));
@@ -402,27 +406,27 @@ function _computeEllipsePoints(increment: number, cx: number, cy: number, rx: nu
allPoints.push([
_offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment)
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment),
]);
for (let angle = radOffset; angle < (Math.PI * 2 + radOffset - 0.01); angle = angle + increment) {
const p: Point = [
_offsetOpt(offset, o) + cx + rx * Math.cos(angle),
_offsetOpt(offset, o) + cy + ry * Math.sin(angle)
_offsetOpt(offset, o) + cy + ry * Math.sin(angle),
];
corePoints.push(p);
allPoints.push(p);
}
allPoints.push([
_offsetOpt(offset, o) + cx + rx * Math.cos(radOffset + Math.PI * 2 + overlap * 0.5),
_offsetOpt(offset, o) + cy + ry * Math.sin(radOffset + Math.PI * 2 + overlap * 0.5)
_offsetOpt(offset, o) + cy + ry * Math.sin(radOffset + Math.PI * 2 + overlap * 0.5),
]);
allPoints.push([
_offsetOpt(offset, o) + cx + 0.98 * rx * Math.cos(radOffset + overlap),
_offsetOpt(offset, o) + cy + 0.98 * ry * Math.sin(radOffset + overlap)
_offsetOpt(offset, o) + cy + 0.98 * ry * Math.sin(radOffset + overlap),
]);
allPoints.push([
_offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset + overlap * 0.5),
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset + overlap * 0.5)
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset + overlap * 0.5),
]);
return [allPoints, corePoints];
@@ -433,21 +437,21 @@ function _arc(increment: number, cx: number, cy: number, rx: number, ry: number,
const points: Point[] = [];
points.push([
_offsetOpt(offset, o) + cx + 0.9 * rx * Math.cos(radOffset - increment),
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment)
_offsetOpt(offset, o) + cy + 0.9 * ry * Math.sin(radOffset - increment),
]);
for (let angle = radOffset; angle <= stp; angle = angle + increment) {
points.push([
_offsetOpt(offset, o) + cx + rx * Math.cos(angle),
_offsetOpt(offset, o) + cy + ry * Math.sin(angle)
_offsetOpt(offset, o) + cy + ry * Math.sin(angle),
]);
}
points.push([
cx + rx * Math.cos(stp),
cy + ry * Math.sin(stp)
cy + ry * Math.sin(stp),
]);
points.push([
cx + rx * Math.cos(stp),
cy + ry * Math.sin(stp)
cy + ry * Math.sin(stp),
]);
return _curve(points, null, o);
}
@@ -466,12 +470,13 @@ function _bezierTo(x1: number, y1: number, x2: number, y2: number, x: number, y:
}
f = preserveVertices ? [x, y] : [x + _offsetOpt(ros[i], o), y + _offsetOpt(ros[i], o)];
ops.push({
op: 'bcurveTo', data: [
op: 'bcurveTo',
data: [
x1 + _offsetOpt(ros[i], o), y1 + _offsetOpt(ros[i], o),
x2 + _offsetOpt(ros[i], o), y2 + _offsetOpt(ros[i], o),
f[0], f[1]
]
f[0], f[1],
],
});
}
return ops;
}
}
+2 -2
View File
@@ -18,5 +18,5 @@ export default {
newSeed(): number {
return RoughGenerator.newSeed();
}
};
},
};
-61
View File
@@ -1,61 +0,0 @@
{
"rules": {
"arrow-parens": true,
"class-name": true,
"indent": [
true,
"spaces",
2
],
"prefer-const": true,
"no-duplicate-variable": true,
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": false,
"no-var-keyword": true,
"one-line": [
true,
"check-open-brace",
"check-whitespace"
],
"quotemark": [
true,
"single",
"avoid-escape"
],
"semicolon": [
true,
"always"
],
"trailing-comma": [
true,
"multiline"
],
"triple-equals": [
true,
"allow-null-check"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"variable-name": [
true,
"ban-keywords"
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}
}