Skip to content

Commit

Permalink
add eslint and fix all issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Aug 8, 2022
1 parent 66a230f commit 06218fd
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 25 deletions.
233 changes: 233 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
env: {
node: true,
mocha: true,
es6: true
},
parserOptions: {
project: ['./tsconfig.json'],
createDefaultProgram: true
},
plugins: [
'@typescript-eslint',
'no-only-tests',
'github'
],
extends: [
'eslint:all',
'plugin:@typescript-eslint/all'
],
rules: {
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/init-declarations': 'off',
'@typescript-eslint/parameter-properties': 'off',
'@typescript-eslint/lines-between-class-members': 'off',
'@typescript-eslint/member-ordering': 'off',
'@typescript-eslint/method-signature-style': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-base-to-string': 'off',
'@typescript-eslint/no-confusing-void-expression': 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extra-parens': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-implicit-any-catch': 'off',
'@typescript-eslint/no-invalid-this': 'off',
'@typescript-eslint/no-magic-numbers': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
//had to add this rule to prevent eslint from crashing
'@typescript-eslint/no-restricted-imports': ['off', {}],
//mitigating this sometimes results in undesirably verbose code. Should investigate enabling again in the future.
'@typescript-eslint/no-unsafe-argument': 'off',
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': [
'error',
'always'
],
'@typescript-eslint/no-shadow': 'off',
'@typescript-eslint/no-this-alias': 'off',
//possibly disable this once we have converted all throw statements to actual errors
'@typescript-eslint/no-throw-literal': 'off',
'@typescript-eslint/no-invalid-void': 'off',
'@typescript-eslint/no-invalid-void-type': 'off',
'@typescript-eslint/no-type-alias': 'off',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars-experimental': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/prefer-for-of': 'off',
'@typescript-eslint/prefer-readonly': 'off',
'@typescript-eslint/prefer-readonly-parameter-types': 'off',
'@typescript-eslint/promise-function-async': 'off',
'@typescript-eslint/quotes': [
'error',
'single',
{
'allowTemplateLiterals': true
}
],
'@typescript-eslint/require-array-sort-compare': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/sort-type-union-intersection-members': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/space-infix-ops': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',
'@typescript-eslint/typedef': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/unified-signatures': 'off',
'array-bracket-newline': 'off',
'array-element-newline': 'off',
'array-type': 'off',
'arrow-body-style': 'off',
'arrow-parens': 'off',
'callback-return': 'off',
'capitalized-comments': 'off',
'class-methods-use-this': 'off',
'complexity': 'off',
'consistent-return': 'off',
'consistent-this': 'off',
'curly': 'error',
'default-case': 'off',
'dot-location': 'off',
'dot-notation': 'off',
'func-style': 'off',
'function-call-argument-newline': 'off',
'function-paren-newline': 'off',
'getter-return': 'off',
'github/array-foreach': 'error',
'guard-for-in': 'off',
'id-length': 'off',
'indent': 'off',
'init-declarations': 'off',
'line-comment-position': 'off',
'linebreak-style': 'off',
'lines-around-comment': 'off',
'lines-between-class-members': 'off',
'max-classes-per-file': 'off',
'max-depth': 'off',
'max-len': 'off',
'max-lines': 'off',
'max-lines-per-function': 'off',
'max-params': 'off',
'max-statements': 'off',
'no-only-tests/no-only-tests': 'error',
'multiline-comment-style': 'off',
'multiline-ternary': 'off',
'new-cap': 'off',
'newline-per-chained-call': 'off',
'no-await-in-loop': 'off',
'no-case-declarations': 'off',
'no-constant-condition': 'off',
'no-console': 'off',
'no-continue': 'off',
'no-else-return': 'off',
'no-empty': 'off',
'no-implicit-coercion': 'off',
'no-inline-comments': 'off',
'no-invalid-this': 'off',
'no-labels': 'off',
'no-lonely-if': 'off',
'no-negated-condition': 'off',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-process-exit': 'off',
'no-prototype-builtins': 'off',
'no-shadow': 'off',
'no-sync': 'off',
'no-ternary': 'off',
'no-undefined': 'off',
'no-underscore-dangle': 'off',
'no-unneeded-ternary': 'off',
'no-useless-escape': 'off',
'no-void': 'off',
'no-warning-comments': 'off',
'object-property-newline': 'off',
'object-shorthand': [
'error',
'never'
],
'one-var': [
'error',
'never'
],
'padded-blocks': 'off',
'prefer-const': 'off',
'prefer-destructuring': 'off',
'prefer-named-capture-group': 'off',
'prefer-template': 'off',
'quote-props': 'off',
'radix': 'off',
'require-atomic-updates': 'off',
'require-unicode-regexp': 'off',
'sort-imports': 'off',
'sort-keys': 'off',
'spaced-comment': 'off',
'space-infix-ops': 'off',
'vars-on-top': 'off',
'wrap-regex': 'off'
},
//disable some rules for certain files
overrides: [{
//these files are getting deleted soon, so ingore the eslint warnings for now
files: ['src/brsTypes/**/*.ts'],
rules: {
'@typescript-eslint/no-invalid-this': 'off',
'@typescript-eslint/method-signature-style': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/prefer-enum-initializers': 'off'
}
},
{
files: ['*.spec.ts'],
rules: {
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars-experimental': 'off',
'@typescript-eslint/dot-notation': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'github/array-foreach': 'off',
'new-cap': 'off',
'no-shadow': 'off',
'no-void': 'off'
}
}, {
files: ['benchmarks/**/*'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/no-var-requires': 'off'
}
}, {
files: ['src/roku-types/data.json'],
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/quotes': 'off',
'no-template-curly-in-string': 'off',
'eol-last': 'off',
'@typescript-eslint/semi': 'off'
}
}, {
files: ['scripts/**/*.ts'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-require-imports': 'off',
'camelcase': 'off'
}
}]
};
17 changes: 9 additions & 8 deletions src/Canvas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color } from "./Color";
import type { Color } from './Color';
import * as Jimp from 'jimp';

export class Canvas {
Expand All @@ -19,7 +19,6 @@ export class Canvas {
for (let i = row.length; i <= x; i++) {
row.push(undefined);
}
return
}

/**
Expand Down Expand Up @@ -85,11 +84,11 @@ export class Canvas {

for (let roundedX = Math.floor(x); roundedX < Math.ceil(x); roundedX++) {
for (let roundedY = Math.floor(y); roundedY < Math.ceil(y); roundedY++) {
let percentX = 1 - Math.abs(x - roundedX)
let percentY = 1 - Math.abs(y - roundedY)
let percent = percentX * percentY
let percentX = 1 - Math.abs(x - roundedX);
let percentY = 1 - Math.abs(y - roundedY);
let percent = percentX * percentY;

const currentAlpha = (this.get(x, y) ?? color.clone()).alpha
const currentAlpha = (this.get(x, y) ?? color.clone()).alpha;
const additionalAlpha = 255 * percent;
//make the pixel more solid by this percentage
const antiAliasedColor = color.clone().setAlpha(
Expand Down Expand Up @@ -132,8 +131,10 @@ export class Canvas {

public write(outPath: string, width: number, height: number) {
let image = new Jimp(width + 2, height + 2, this.backgroundColor.toInteger(), (err, image) => {
if (err) throw err
})
if (err) {
throw err;
}
});
for (let y = 0; y < this.grid.length; y++) {
const row = this.grid[y];
for (let x = 0; x < row.length; x++) {
Expand Down
7 changes: 4 additions & 3 deletions src/Color.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from "chai";
import { Color, ColorLike, RgbaArray } from "./Color";
import { expect } from 'chai';
import type { ColorLike, RgbaArray } from './Color';
import { Color } from './Color';

describe('Color', () => {
function expectColor(input: ColorLike, expected: RgbaArray) {
Expand Down Expand Up @@ -88,4 +89,4 @@ describe('Color', () => {
);
});
});
});
});
4 changes: 2 additions & 2 deletions src/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Color {
/**
* The green value
*/
public get green() {
public get green() {
return this.value[1];
}
public set green(value) {
Expand Down Expand Up @@ -216,7 +216,7 @@ function extractHex(value: string) {
if (parts) {
//remove the full match so we can keep just the gropus
parts.shift();
return parts.map(x => parseInt(x, 16))
return parts.map(x => parseInt(x, 16));
}
return parts ?? undefined;
}
Expand Down
8 changes: 4 additions & 4 deletions src/NinePatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export class NinePatcher {
const canvas = new Canvas(backgroundColor);
drawCircle(canvas, {
radius: borderRadius,
borderColor,
borderWidth,
fillColor,
borderColor: borderColor,
borderWidth: borderWidth,
fillColor: fillColor
});
canvas.translate(1, 1);
const black = new Color([0, 0, 0, 255]);
Expand All @@ -59,7 +59,7 @@ export class NinePatcher {
canvas.set(black, 0, centerPoint);
canvas.set(black, centerPoint, 0);

const outPath = path.resolve(this.outDir, config.outFile)
const outPath = path.resolve(this.outDir, config.outFile);
// console.log(canvas.toString());
canvas.write(outPath, width, height);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { NinePatcher } from "./NinePatcher";
export { NinePatcher } from './NinePatcher';
15 changes: 8 additions & 7 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Canvas } from "./Canvas";
import { Color } from "./Color";
import { parse as parseJsonc, ParseError, printParseErrorCode } from 'jsonc-parser';
import type { Canvas } from './Canvas';
import type { Color } from './Color';
import type { ParseError } from 'jsonc-parser';
import { parse as parseJsonc, printParseErrorCode } from 'jsonc-parser';
import * as fsExtra from 'fs-extra';

export function readJsoncSync<T>(path: string) {
Expand Down Expand Up @@ -40,16 +41,16 @@ export function drawCircle(canvas: Canvas, options: { radius: number; borderColo
// }
}

export function drawCircumference(canvas: Canvas, options: { radius: number, color: Color, antiAlias: boolean, strokeWidth: number }) {
export function drawCircumference(canvas: Canvas, options: { radius: number; color: Color; antiAlias: boolean; strokeWidth: number }) {
const strokeWidth = options.strokeWidth ?? 1;
//the actual radius should represent the center of the line
const radius = options.radius - (strokeWidth / 2);
const theta_scale = 0.001; //Set lower to add more points
const sizeValue = (2.0 * Math.PI) / theta_scale;
const thetaScale = 0.001; //Set lower to add more points
const sizeValue = (2.0 * Math.PI) / thetaScale;
let stepCount = Math.floor(sizeValue) + 1;
let theta = 0;
for (let i = 0; i < stepCount; i++) {
theta += (2.0 * Math.PI * theta_scale);
theta += (2.0 * Math.PI * thetaScale);
let x = radius * Math.cos(theta);
let y = radius * Math.sin(theta);
//draw where 0,0 is the leftmost and topmost coordinate
Expand Down

0 comments on commit 06218fd

Please sign in to comment.