Skip to content

Commit

Permalink
Migrate linter (#200)
Browse files Browse the repository at this point in the history
Migrate linter from tslint to eslint
  • Loading branch information
thekevinscott authored Feb 13, 2022
1 parent dfed1df commit a53c271
Show file tree
Hide file tree
Showing 26 changed files with 743 additions and 536 deletions.
146 changes: 0 additions & 146 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,149 +144,3 @@ jobs:

- name: 'Integration Tests'
run: yarn test:integration:node --ci

on: [push]

jobs:
unit:
name: 'Tests: Unit'
runs-on: ubuntu-latest
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '14'

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: 'Installing'
run: yarn

- name: 'Unit Tests'
run: yarn test:unit

- name: 'Codecov'
uses: codecov/codecov-action@v1
with:
directory: ./packages/upscalerjs/coverage
verbose: true

integration-browser-browserstack:
name: 'Tests: Integration / Browser / Browserstack'
runs-on: ubuntu-latest
steps:
- name: 'BrowserStack Env Setup' # Invokes the setup-env action
uses: browserstack/github-actions/setup-env@master
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

- name: 'Checkout repository'
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: 'Installing'
env:
NODE_OPTIONS: --max_old_space_size=8192
run: yarn

- name: 'Integration Tests'
run: yarn test:integration:browserstack --ci
env:
NODE_OPTIONS: --max_old_space_size=8192

integration-browser-local:
name: 'Tests: Integration / Browser / Local'
runs-on: ubuntu-latest
steps:
- name: 'BrowserStack Env Setup' # Invokes the setup-env action
uses: browserstack/github-actions/setup-env@master
with:
username: ${{ secrets.BROWSERSTACK_USERNAME }}
access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}

- name: 'Checkout repository'
uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: 'Installing'
env:
NODE_OPTIONS: --max_old_space_size=8192
run: yarn

- name: 'Integration Tests'
run: yarn test:integration:browser --ci
env:
NODE_OPTIONS: --max_old_space_size=8192


integration-node-local-14:
name: 'Tests: Integration / Node / Local / v14'
runs-on: ubuntu-latest
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '14'

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: 'Installing'
env:
NODE_OPTIONS: --max_old_space_size=8192
run: yarn

- name: 'Installing Node-specific deps'
env:
NODE_OPTIONS: --max_old_space_size=8192
run: cd test/lib/node && yarn

- name: 'Integration Tests'
run: yarn test:integration:node --ci

integration-node-local-16:
name: 'Tests: Integration / Node / Local / v16'
runs-on: ubuntu-latest
steps:
- name: 'Checkout repository'
uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '16'

- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

- name: 'Installing'
env:
NODE_OPTIONS: --max_old_space_size=8192
run: yarn

- name: 'Installing Node-specific deps'
env:
NODE_OPTIONS: --max_old_space_size=8192
run: cd test/lib/node && yarn

- name: 'Integration Tests'
run: yarn test:integration:node --ci
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"canvas": "^2.9.0",
"codecov": "^3.7.2",
"docsify-cli": "^4.4.2",
"tslint-to-eslint-config": "1.0.0",
"dotenv": "^8.2.0",
"esbuild": "^0.9.6",
"html-webpack-plugin": "^5.3.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/upscalerjs/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.generated.ts
**/*.test.ts
30 changes: 30 additions & 0 deletions packages/upscalerjs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
"env": {
"browser": true,
"es6": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier",
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/semi": ["error", "always"],
"comma-dangle": ["error", "always"],
"curly": ["error", "all"],
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
}
};
21 changes: 12 additions & 9 deletions packages/upscalerjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,24 @@
],
"scripts": {
"build": "rimraf dist && yarn build:node && yarn build:browser",

"build:browser": "rimraf dist/browser && mkdir -p dist/browser && yarn scaffold:platform 'browser' && yarn lerna run build:umd && yarn lerna run build:esm && mv dist/esm dist/browser/esm",
"build:node": "rimraf dist/node && mkdir -p dist/node && yarn scaffold:platform 'node' && yarn lerna run build:cjs && mv dist/cjs dist/node/cjs",
"build:node-gpu": "rimraf dist/node-gpu && mkdir -p dist/node-gpu && yarn scaffold:platform 'node-gpu' && yarn lerna run build:cjs && mv dist/cjs dist/node-gpu/cjs",

"build:cjs": "tsc --module commonjs --target es5 --outDir dist/cjs",
"build:esm": "tsc --module esnext --moduleResolution node --target esnext --outDir dist/esm",
"build:umd:tsc": "tsc --moduleResolution node --module es2015 --target es5 --outDir dist/tmp",
"build:umd:rollup": "yarn rollup -c rollup.config.js --failAfterWarnings",
"build:umd:generate": "yarn build:umd:tsc && yarn build:umd:rollup",
"build:umd:compress": "uglifyjs --source-map --comments --output dist/browser/umd/upscaler.min.js -- dist/browser/umd/upscaler.js",
"build:umd": "yarn build:umd:generate && yarn build:umd:compress && rimraf dist/tmp",

"scaffold:platform": "ts-node ../../scripts/scaffold-platform.ts",

"docs:serve": "docsify serve docs --port 3030",
"prepare": "yarn build",
"preversion": "yarn lint",
"prepublishOnly": "yarn test && yarn lint",
"format": "echo 'Formatting code' && prettier --write \"src/**/*.ts\"",
"lint": "echo 'Linting code' && tslint -p tsconfig.json",
"lint": "eslint -c .eslintrc.js src --ext .ts",
"test": "jest --config jestconfig.json",

"watch": "chokidar \"src\" -c \"yarn build\" -i \"test.ts\" -i \"generated.ts\"",
"watch:esm": "chokidar \"src\" -c \"yarn build:esm\" -i \"test.ts\" -i \"generated.ts\"",
"watch:umd": "chokidar \"src\" -c \"yarn build:umd\" -i \"test.ts\" -i \"generated.ts\"",
Expand All @@ -79,8 +74,16 @@
"@tensorflow/tfjs": "^3.13.0"
},
"dependencies": {
"tensor-as-base64": "^0.1.1",
"isomorphic-fetch": "^3.0.0"
"isomorphic-fetch": "^3.0.0",
"tensor-as-base64": "^0.1.1"
},
"gitHead": "cccae63a0a7aeccaa78d30e55a8e12ec72f5c19f"
"gitHead": "cccae63a0a7aeccaa78d30e55a8e12ec72f5c19f",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"eslint": "^8.8.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jsdoc": "^37.8.2",
"eslint-plugin-prefer-arrow": "^1.2.3"
}
}
3 changes: 1 addition & 2 deletions packages/upscalerjs/src/cjs.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// tslint:disable-next-line:no-var-requires
module.exports = require('./index').default;
module.exports = require('./index').default; // eslint-disable-line
46 changes: 23 additions & 23 deletions packages/upscalerjs/src/image.browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSDOM } from 'jsdom';
import { getImageAsPixels, getInvalidTensorError } from './image.browser';
import { JSDOM, } from 'jsdom';
import { getImageAsPixels, getInvalidTensorError, } from './image.browser';
import * as tf from '@tensorflow/tfjs';
jest.mock('@tensorflow/tfjs', () => {
const tf = jest.requireActual('@tensorflow/tfjs');
Expand All @@ -10,24 +10,24 @@ jest.mock('@tensorflow/tfjs', () => {
fromPixels: () => {
return {
expandDims: () => {
return tf.tensor([1]);
}
return tf.tensor([1,]);
},
};
}
}
}
},
},
};
});
import * as utils from './utils';
jest.mock('./utils', () => {
const utils = jest.requireActual('./utils');
return {
...utils,
isFourDimensionalTensor: jest.fn((pixels) => utils.isFourDimensionalTensor(pixels)),
}
};
});
const mockedUtils = utils as jest.Mocked<typeof utils>;

const { window } = new JSDOM('', { resources: 'usable' });
const { window, } = new JSDOM('', { resources: 'usable', });
global.Image = window.Image;
global.HTMLImageElement = window.HTMLImageElement;
const origSrc = Object.getOwnPropertyDescriptor(Image.prototype, 'src');
Expand All @@ -42,10 +42,10 @@ describe('Image', () => {
describe('getImageAsPixels', () => {
afterEach(() => {
Object.defineProperty(global.Image.prototype, 'src', origSrc);
})
});

it('loads an Image() if given a string as input', async () => {
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()))
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()));
Object.defineProperty(global.Image.prototype, 'src', {
set() {
return mockSet(this);
Expand All @@ -59,7 +59,7 @@ describe('Image', () => {

it('handles a rejected Image() if given a string as input', async () => {
const error = 'some error';
const mockSet = jest.fn((_this) => setTimeout(() => _this.onerror(new Error(error))))
const mockSet = jest.fn((_this) => setTimeout(() => _this.onerror(new Error(error))));
Object.defineProperty(global.Image.prototype, 'src', {
set() {
return mockSet(this);
Expand All @@ -75,7 +75,7 @@ describe('Image', () => {
const img = new Image();
img.src = 'foobar';
img.crossOrigin = 'anonymous';
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()))
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()));
Object.defineProperty(global.Image.prototype, 'src', {
set() {
return mockSet(this);
Expand All @@ -87,8 +87,8 @@ describe('Image', () => {
});

it('reads a rank 4 tensor directly without manipulation', async () => {
const input: tf.Tensor4D = tf.tensor([[[[1]]]]);
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()))
const input: tf.Tensor4D = tf.tensor([[[[1,],],],]);
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()));
Object.defineProperty(global.Image.prototype, 'src', {
set() {
return mockSet(this);
Expand All @@ -98,12 +98,12 @@ describe('Image', () => {
expect(mockSet).toHaveBeenCalledTimes(0);
expect(result.canDispose).toEqual(false);
expect(result.tensor).toBe(input);
expect(result.tensor.shape).toEqual([1,1,1,1]);
expect(result.tensor.shape).toEqual([1,1,1,1,]);
});

it('reads a rank 3 tensor and expands to rank 4', async () => {
const input: tf.Tensor3D = tf.tensor([[[1]]]);
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()))
const input: tf.Tensor3D = tf.tensor([[[1,],],]);
const mockSet = jest.fn((_this) => setTimeout(() => _this.onload()));
Object.defineProperty(global.Image.prototype, 'src', {
set() {
return mockSet(this);
Expand All @@ -112,21 +112,21 @@ describe('Image', () => {
const result = await getImageAsPixels(input);
expect(mockSet).toHaveBeenCalledTimes(0);
expect(result.canDispose).toEqual(true);
expect(result.tensor.shape).toEqual([1,1,1,1]);
expect(result.tensor.shape).toEqual([1,1,1,1,]);
});

it('handles an invalid (too small) tensor input', async () => {
const input = tf.tensor([[1]]);
const input = tf.tensor([[1,],]);
await expect(() => getImageAsPixels(input as any))
.rejects
.toThrow(getInvalidTensorError(input))
.toThrow(getInvalidTensorError(input));
});

it('handles an invalid (too large) tensor input', async () => {
const input = tf.tensor([[[[[1]]]]]);
const input = tf.tensor([[[[[1,],],],],]);
await expect(() => getImageAsPixels(input as any))
.rejects
.toThrow(getInvalidTensorError(input))
.toThrow(getInvalidTensorError(input));
});
});
});
4 changes: 2 additions & 2 deletions packages/upscalerjs/src/image.browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tf } from './dependencies.generated';
import { isFourDimensionalTensor, isThreeDimensionalTensor, isTensor, isString } from './utils';
import { tf, } from './dependencies.generated';
import { isFourDimensionalTensor, isThreeDimensionalTensor, isTensor, isString, } from './utils';

export const getInvalidTensorError = (input: tf.Tensor) => new Error(
[
Expand Down
4 changes: 2 additions & 2 deletions packages/upscalerjs/src/image.node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tf } from './dependencies.generated';
import { isFourDimensionalTensor, isThreeDimensionalTensor, isTensor, isString } from './utils';
import { tf, } from './dependencies.generated';
import { isFourDimensionalTensor, isThreeDimensionalTensor, isTensor, isString, } from './utils';

export const getInvalidTensorError = (input: tf.Tensor) => new Error(
[
Expand Down
4 changes: 2 additions & 2 deletions packages/upscalerjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './upscaler';
export { getRowsAndColumns, getTensorDimensions } from './upscale';
export { default, } from './upscaler';
export { getRowsAndColumns, getTensorDimensions, } from './upscale';
Loading

0 comments on commit a53c271

Please sign in to comment.