Skip to content

Commit

Permalink
chore: replace tslint with eslint (#433)
Browse files Browse the repository at this point in the history
- Replace tslint with eslint
- Run prettier as eslint plugin
  • Loading branch information
just-jeb authored Jan 7, 2024
1 parent 1dbd7d6 commit 427d83d
Show file tree
Hide file tree
Showing 26 changed files with 3,320 additions and 2,175 deletions.
24 changes: 24 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"prettier"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"prettier/prettier": "error",
// TODO: remove this override
"@typescript-eslint/no-explicit-any": "off"
},
"env": {
"browser": true,
"es2021": true,
"node": true
}
}
8 changes: 1 addition & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
.DS_Store
node_modules

coverage
lib
lib-esm
lib-fesm
umd
typings
docs
dist

## this is generated by `npm pack`
*.tgz
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run ts:style && npm run test:only-changed
npm run eslint && npm run test:only-changed
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120
}
8 changes: 3 additions & 5 deletions e2e/umd-import-min.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const {cold, hot, time} = require('../umd/jest-marbles.min');
const { cold, hot, time } = require('../dist/umd/jest-marbles.min');

/**
* Created by Evgeny Barabanov on 05/03/2018.
*/
describe('Imports test', () => {

it('All the function should exist', () => {
const c = cold('a|');
const h = hot('a|');
Expand All @@ -15,8 +14,7 @@ describe('Imports test', () => {
});

it('Should work with value objects', () => {
const c = cold('--a-|', {a: {prop: "blah"}});
expect(c).toBeObservable(cold('--a-|', {a: {prop: "blah"}}));
const c = cold('--a-|', { a: { prop: 'blah' } });
expect(c).toBeObservable(cold('--a-|', { a: { prop: 'blah' } }));
});

});
28 changes: 13 additions & 15 deletions e2e/umd-import.spec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
const {cold, hot, time} = require('../umd/jest-marbles');
const { cold, hot, time } = require('../dist/umd/jest-marbles');

/**
* Created by Evgeny Barabanov on 05/03/2018.
*/
describe('Imports test', () => {
it('All the function should exist', () => {
const c = cold('a|');
const h = hot('a|');
const t = time('a|');
expect(c).not.toBeNull();
expect(h).not.toBeNull();
expect(t).not.toBeNull();
});

it('All the function should exist', () => {
const c = cold('a|');
const h = hot('a|');
const t = time('a|');
expect(c).not.toBeNull();
expect(h).not.toBeNull();
expect(t).not.toBeNull();
});

it('Should work with value objects', () => {
const c = cold('--a-|', {a: {prop: "blah"}});
expect(c).toBeObservable(cold('--a-|', {a: {prop: "blah"}}));
});

it('Should work with value objects', () => {
const c = cold('--a-|', { a: { prop: 'blah' } });
expect(c).toBeObservable(cold('--a-|', { a: { prop: 'blah' } }));
});
});
45 changes: 23 additions & 22 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ export type ObservableWithSubscriptions = ColdObservable | HotObservable;
export { Scheduler } from './src/rxjs/scheduler';

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R, T> {
toBeObservable(observable: ObservableWithSubscriptions): void;
interface Matchers<R extends void | Promise<void>> {
toBeObservable(observable: ObservableWithSubscriptions): R;

toHaveSubscriptions(marbles: string | string[]): void;
toHaveSubscriptions(marbles: string | string[]): R;

toHaveNoSubscriptions(): void;
toHaveNoSubscriptions(): R;

toBeMarble(marble: string): void;
toBeMarble(marble: string): R;

toSatisfyOnFlush(func: () => void): void;
toSatisfyOnFlush(func: () => void): R;
}
}
}

// @ts-ignore
declare module "expect" {
interface Matchers<R = void> {
toBeObservable(observable: ObservableWithSubscriptions): void;
toHaveSubscriptions(marbles: string | string[]): void;
toHaveNoSubscriptions(): void;
toBeMarble(marble: string): void;
toSatisfyOnFlush(func: () => void): void;
declare module 'expect' {
interface Matchers<R extends void | Promise<void>> {
toBeObservable(observable: ObservableWithSubscriptions): R;
toHaveSubscriptions(marbles: string | string[]): R;
toHaveNoSubscriptions(): R;
toBeMarble(marble: string): R;
toSatisfyOnFlush(func: () => void): R;
}
}

export function hot(marbles: string, values?: any, error?: any): HotObservable {
export function hot(marbles: string, values?: object, error?: object): HotObservable {
return new HotObservable(stripAlignmentChars(marbles), values, error);
}

export function cold(marbles: string, values?: any, error?: any): ColdObservable {
export function cold(marbles: string, values?: object, error?: object): ColdObservable {
return new ColdObservable(stripAlignmentChars(marbles), values, error);
}

Expand All @@ -48,11 +48,10 @@ export function time(marbles: string): number {

const dummyResult = {
message: () => '',
pass: true
pass: true,
};

expect.extend({

toHaveSubscriptions(actual: ObservableWithSubscriptions, marbles: string | string[]) {
const sanitizedMarbles = Array.isArray(marbles) ? marbles.map(stripAlignmentChars) : stripAlignmentChars(marbles);
Scheduler.get().expectSubscriptions(actual.getSubscriptions()).toBe(sanitizedMarbles);
Expand Down Expand Up @@ -81,17 +80,19 @@ expect.extend({
flushTests[flushTests.length - 1].ready = true;
onFlush.push(func);
return dummyResult;
}
},
});

let onFlush: (() => void)[] = [];

beforeEach(() => { Scheduler.init(); onFlush = []; });
beforeEach(() => {
Scheduler.init();
onFlush = [];
});
afterEach(() => {
Scheduler.get().flush();
while (onFlush.length > 0) {
// @ts-ignore
onFlush.shift()();
onFlush.shift()?.();
}
Scheduler.reset();
});
Loading

0 comments on commit 427d83d

Please sign in to comment.