Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate to expecttype eslint rules #7416

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ jobs:
run: yarn workspace rxjs build
- name: rxjs test
run: yarn workspace rxjs test
- name: rxjs dtslint
run: yarn workspace rxjs dtslint
- name: rxjs test:import
run: yarn workspace rxjs test:import
- name: rxjs test:esm
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"dependencies": {},
"devDependencies": {
"@nx/js": "17.3.0-beta.4",
"nx": "17.3.0-beta.4"
"nx": "17.3.0-beta.4",
"typescript": "~4.9.4"
}
}
7 changes: 3 additions & 4 deletions packages/rxjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"scripts": {
"changelog": "npx conventional-changelog-cli -p angular -i CHANGELOG.md -s",
"lint": "eslint --ext=ts,js src spec spec-dtslint",
"dtslint": "npm run lint && tsc -b ./src/tsconfig.types.json",
"test": "yarn build && cross-env TS_NODE_PROJECT=tsconfig.mocha.json mocha --config spec/support/.mocharc.js \"spec/**/*-spec.ts\"",
"test:esm": "node spec/module-test-spec.mjs",
"test:circular": "dependency-cruiser --validate .dependency-cruiser.json -x \"^node_modules\" dist/esm",
Expand All @@ -83,7 +82,6 @@
"build:clean": "shx rm -rf ./dist",
"build": "yarn build:clean && yarn compile && node ./tools/generate-alias.js",
"watch": "nodemon -w \"src/\" -w \"spec/\" -e ts -x npm test",
"watch:dtslint": "nodemon -w \"src/\" -w \"spec-dtslint/\" -e ts -x yarn dtslint",
"copy_common_package_files": "node ../../scripts/copy-common-package-files.js"
},
"repository": {
Expand Down Expand Up @@ -143,15 +141,16 @@
"@types/shelljs": "^0.8.8",
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.9",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"chai": "^4.3.7",
"color": "3.0.0",
"colors": "1.1.2",
"cross-env": "5.1.3",
"cz-conventional-changelog": "1.2.0",
"dependency-cruiser": "^9.12.0",
"eslint": "^8.52.0",
"eslint-plugin-expect-type": "^0.3.0",
"form-data": "^3.0.0",
"fs-extra": "^8.1.0",
"husky": "^4.2.5",
Expand Down
8 changes: 8 additions & 0 deletions packages/rxjs/spec-dtslint/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": [
"plugin:expect-type/recommended"
],
"plugins": [
"expect-type"
]
}
2 changes: 1 addition & 1 deletion packages/rxjs/spec-dtslint/firstValueFrom-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { firstValueFrom } from 'rxjs';
import { a$ } from 'helpers';
import { a$ } from './helpers';

describe('firstValueFrom', () => {
it('should infer the element type', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rxjs/spec-dtslint/lastValueFrom-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { lastValueFrom } from 'rxjs';
import { a$ } from 'helpers';
import { a$ } from './helpers';

describe('lastValueFrom', () => {
it('should infer the element type', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rxjs/spec-dtslint/observables/forkJoin-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { a$, b$, c$ } from 'helpers';
import { a$, b$, c$ } from '../helpers';
import { of, forkJoin } from 'rxjs';

describe('deprecated rest args', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/rxjs/spec-dtslint/observables/iif-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { a$, b$ } from 'helpers';
import { a$, b$ } from '../helpers';
import { iif, EMPTY } from 'rxjs';

const randomBoolean = () => Math.random() > 0.5;
Expand Down Expand Up @@ -31,4 +31,4 @@ it('should support inference from a predicate that returns any', () => {
}

const o$ = iif(alwaysTrueButReturnsAny, a$, b$) // $ExpectType Observable<A | B>
});
});
2 changes: 1 addition & 1 deletion packages/rxjs/spec-dtslint/operators/concatWith-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { of } from 'rxjs';
import { concatWith } from 'rxjs/operators';
import { a$, b$, c$, d$, e$ } from 'helpers';
import { a$, b$, c$, d$, e$ } from '../helpers';

it('should support rest params', () => {
const arr = [b$, c$];
Expand Down
15 changes: 0 additions & 15 deletions packages/rxjs/spec-dtslint/operators/every-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,3 @@ it('should handle the Boolean constructor', () => {
const d = of(NaN, NaN, NaN).pipe(every(Boolean)); // $ExpectType Observable<boolean>
const e = of(0, 1, 0).pipe(every(Boolean)); // $ExpectType Observable<boolean>
})

it('should support this', () => {
const thisArg = { limit: 5 };
const a = of(1, 2, 3).pipe(every(function (val) {
const limit = this.limit; // $ExpectType number
return val < limit;
}, thisArg));
});

it('should deprecate thisArg usage', () => {
const a = of(1, 2, 3).pipe(every(Boolean)); // $ExpectNoDeprecation
const b = of(1, 2, 3).pipe(every(Boolean, {})); // $ExpectDeprecation
const c = of(1, 2, 3).pipe(every((value) => Boolean(value))); // $ExpectNoDeprecation
const d = of(1, 2, 3).pipe(every((value) => Boolean(value), {})); // $ExpectDeprecation
});
98 changes: 47 additions & 51 deletions packages/rxjs/spec-dtslint/operators/expand-spec.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
import { of, asyncScheduler } from 'rxjs';
import { expand } from 'rxjs/operators';

it('should infer correctly', () => {
const o = of(1, 2, 3).pipe(expand(value => of(value))); // $ExpectType Observable<number>
const p = of(1, 2, 3).pipe(expand(value => [value])); // $ExpectType Observable<number>
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve(value))); // $ExpectType Observable<number>
});

it('should infer correctly with a different type as the source', () => {
const o = of(1, 2, 3).pipe(expand(value => of('foo'))); // $ExpectType Observable<string>
const p = of(1, 2, 3).pipe(expand(value => ['foo'])); // $ExpectType Observable<string>
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve('foo'))); // $ExpectType Observable<string>
});

it('should support a project function with index', () => {
const o = of(1, 2, 3).pipe(expand((value, index) => of(index))); // $ExpectType Observable<number>
});

it('should support concurrent parameter', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 47)); // $ExpectType Observable<number>
});

it('should support a scheduler', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, asyncScheduler)); // $ExpectType Observable<number>
});

it('should enforce types', () => {
const o = of(1, 2, 3).pipe(expand()); // $ExpectError
});

it('should enforce project types', () => {
const o = of(1, 2, 3).pipe(expand((value: string, index) => of(1))); // $ExpectError
const p = of(1, 2, 3).pipe(expand((value, index: string) => of(1))); // $ExpectError
});

it('should enforce project return type', () => {
const o = of(1, 2, 3).pipe(expand(value => 1)); // $ExpectError
});

it('should enforce concurrent type', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 'foo')); // $ExpectError
});

it('should enforce scheduler type', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, 'foo')); // $ExpectError
});

it('should support union types', () => {
const o = of(1).pipe(expand(x => typeof x === 'string' ? of(123) : of('test'))); // $ExpectType Observable<string | number>
});
import { of, asyncScheduler } from 'rxjs';
import { expand } from 'rxjs/operators';
Copy link
Contributor Author

@43081j 43081j Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whitespace change seems to be that the original file had CRLF. my editor read the editorconfig and changed it to LF


it('should infer correctly', () => {
const o = of(1, 2, 3).pipe(expand(value => of(value))); // $ExpectType Observable<number>
const p = of(1, 2, 3).pipe(expand(value => [value])); // $ExpectType Observable<number>
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve(value))); // $ExpectType Observable<number>
});

it('should infer correctly with a different type as the source', () => {
const o = of(1, 2, 3).pipe(expand(value => of('foo'))); // $ExpectType Observable<string>
const p = of(1, 2, 3).pipe(expand(value => ['foo'])); // $ExpectType Observable<string>
const q = of(1, 2, 3).pipe(expand(value => Promise.resolve('foo'))); // $ExpectType Observable<string>
});

it('should support a project function with index', () => {
const o = of(1, 2, 3).pipe(expand((value, index) => of(index))); // $ExpectType Observable<number>
});

it('should support concurrent parameter', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 47)); // $ExpectType Observable<number>
});

it('should enforce types', () => {
const o = of(1, 2, 3).pipe(expand()); // $ExpectError
});

it('should enforce project types', () => {
const o = of(1, 2, 3).pipe(expand((value: string, index) => of(1))); // $ExpectError
const p = of(1, 2, 3).pipe(expand((value, index: string) => of(1))); // $ExpectError
});

it('should enforce project return type', () => {
const o = of(1, 2, 3).pipe(expand(value => 1)); // $ExpectError
});

it('should enforce concurrent type', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 'foo')); // $ExpectError
});

it('should enforce scheduler type', () => {
const o = of(1, 2, 3).pipe(expand(value => of(1), 47, 'foo')); // $ExpectError
});

it('should support union types', () => {
const o = of(1).pipe(expand(x => typeof x === 'string' ? of(123) : of('test'))); // $ExpectType Observable<string | number>
});
1 change: 0 additions & 1 deletion packages/rxjs/src/internal/operators/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function every<T>(predicate: (value: T, index: number) => boolean): Opera
* ```
*
* @param predicate A function for determining if an item meets a specified condition.
* @param thisArg Optional object to use for `this` in the callback.
* @return A function that returns an Observable of booleans that determines if
* all items of the source Observable meet the condition specified.
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/rxjs/src/internal/operators/expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export function expand<T, O extends ObservableInput<unknown>>(
* or the output Observable, returns an Observable.
* @param concurrent Maximum number of input Observables being subscribed to
* concurrently.
* @param scheduler The {@link SchedulerLike} to use for subscribing to
* each projected inner Observable.
* @return A function that returns an Observable that emits the source values
* and also result of applying the projection function to each value emitted on
* the output Observable and merging the results of the Observables obtained
Expand Down
Loading
Loading