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

Tuning eslint #7391

Closed
wants to merge 9 commits into from
Closed
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
185 changes: 0 additions & 185 deletions apps/rxjs.dev/.eslintrc.json

This file was deleted.

7 changes: 0 additions & 7 deletions apps/rxjs.dev/package.json
Original file line number Diff line number Diff line change
@@ -76,8 +76,6 @@
"@types/lunr": "^2.3.3",
"@types/node": "^12.11.1",
"@types/svgo": "^1.3.3",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"archiver": "^3.0.0",
"canonical-path": "^1.0.0",
"chalk": "^2.1.0",
@@ -88,11 +86,6 @@
"css-selector-parser": "^1.3.0",
"dgeni": "^0.4.14",
"dgeni-packages": "^0.30.0",
"eslint": "^8.51.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jasmine": "^4.1.3",
"eslint-plugin-jsdoc": "^46.8.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"firebase-tools": "^9.3.0",
"fs-extra": "^8.0.1",
"globby": "^9.2.0",
2 changes: 1 addition & 1 deletion apps/rxjs.dev/src/app/custom-elements/api/api.service.ts
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ export class ApiService implements OnDestroy {
* API sections is an array of Angular top modules and metadata about their API documents (items).
* Updates `sections` observable
*
* @param {string} [src] - Name of the api list JSON file
* @param [src] - Name of the api list JSON file
*/
fetchSections(src?: string) {
// TODO: get URL by configuration?
Original file line number Diff line number Diff line change
@@ -37,9 +37,9 @@ export class PrettyPrinter {

/**
* Format code snippet as HTML
* @param {string} code - the code snippet to format; should already be HTML encoded
* @param {string} [language] - The language of the code to render (could be javascript, html, typescript, etc)
* @param {string|number} [linenums] - Whether to display line numbers:
* @param code - the code snippet to format; should already be HTML encoded
* @param [language] - The language of the code to render (could be javascript, html, typescript, etc)
* @param [linenums] - Whether to display line numbers:
* - false: don't display
* - true: do display
* - number: do display but start at the given number
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ describe('ContributorListComponent', () => {
return comp;
}

interface SearchResult { [index: string]: string; };
interface SearchResult { [index: string]: string; }

class TestLocationService {
searchResult: SearchResult = {};
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ export class ResourceService {

(categories as ConnectableObservable<Category[]>).connect();
return categories;
};
}
}

// Extract sorted Category[] from resource JSON data
2 changes: 1 addition & 1 deletion apps/rxjs.dev/src/app/search/search.worker.ts
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ interface EncodedPage {
addEventListener('message', handleMessage);

const customLunr = function (config: lunr.ConfigFunction) {
var builder = new lunr.Builder();
const builder = new lunr.Builder();
builder.pipeline.add(lunr.trimmer, lunr.stemmer);
builder.searchPipeline.add(lunr.stemmer);
config.call(builder, builder);
2 changes: 1 addition & 1 deletion apps/rxjs.dev/src/app/shared/deployment.service.ts
Original file line number Diff line number Diff line change
@@ -14,4 +14,4 @@ export class Deployment {
mode: string = this.location.search()['mode'] || environment.mode;

constructor(private location: LocationService) {}
};
}
2 changes: 1 addition & 1 deletion apps/rxjs.dev/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* SystemJS module definition */
declare var module: NodeModule;
declare let module: NodeModule;
interface NodeModule {
id: string;
}
Original file line number Diff line number Diff line change
@@ -7,33 +7,33 @@ import { generateUniqueId } from './generateUniqueId';
* Depth is added to better determine later if it's an inital question
*
* @export
* @param {Tree} tree
* @param {number} [depth=0]
* @param tree
* @param [depth=0]
* @requires generateUniqueId
* @returns {Tree}
* @returns
*/
export function addUniqueId(tree: TreeNodeRaw[], depth = 0): TreeNode[] {
return tree.map(node => {
return tree.map((node) => {
let treeNode: TreeNode;
treeNode = {
label: node.label,
id: generateUniqueId(),
depth // used later in extractInitialSequence to determine the initial options
depth, // used later in extractInitialSequence to determine the initial options
};

if (node.children) {
const children = addUniqueId(node.children, depth + 1);
treeNode = {
...treeNode,
children,
options: children.map(({ id }) => id)
options: children.map(({ id }) => id),
};
}

if (node.method) {
treeNode = {
...treeNode,
method: node.method
method: node.method,
};
}

6 changes: 3 additions & 3 deletions apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.ts
Original file line number Diff line number Diff line change
@@ -7,12 +7,12 @@ import { decisionTreeReducer } from './decisionTreeReducer';
* Main build script, outputs the decision tree.
*
* @export
* @param {FlattenedApiList} apiList
* @param {Tree} tree
* @param apiList
* @param tree
* @requires addUniqueId
* @requires extractInitialSequence
* @requires decisionTreeReducer
* @returns {DecisionTree}
* @returns
*/
export function build(apiList: FlattenedApiList, tree: TreeNodeRaw[]): DecisionTree {
const nodesWithUniqueIds = addUniqueId(tree);
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@ import {
* Helps build the view model.
*
* @export
* @param {Tree} tree
* @param {FlattenedApiList} apiList
* @returns {DecisionTree}
* @param tree
* @param apiList
* @returns
*/
export function decisionTreeReducer(
tree: TreeNode[],
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ import { TreeNode } from './interfaces';
* Strip out initial sequence and add to tree
*
* @export
* @param {Tree} tree
* @returns {{id: string, options: string[]}}
* @param tree
* @returns
*/
export function extractInitialSequence(tree: TreeNode[]): {id: string, options: string[]} {
return {
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ import { isStable } from './helpers';
* Makes navigation easier.
*
* @export
* @param {ApiListNode[]} [apiList=[]]
* @param [apiList=[]]
* @requires isStable
* @returns {FlattenedApiList}
* @returns
* @todo create better type lenses - inference is not working well here
*/
export function flattenApiList(apiList: ApiListNode[]): FlattenedApiList {
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import { randomBytes } from 'crypto';
*
* @export
* @requires crypto:randomByes
* @returns {string}
* @returns
*/
export function generateUniqueId(): string {
return randomBytes(2).toString('hex');
13 changes: 6 additions & 7 deletions apps/rxjs.dev/tools/decision-tree-generator/src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
* We don't want to point people to deprecated API references.
*
* @export
* @param {string} stability
* @returns {boolean}
* @param stability
* @returns
*/
export function isStable(stability: string): boolean {
return stability !== 'deprecated';
@@ -17,7 +17,7 @@ export function isStable(stability: string): boolean {
* Recursively count the number of tree nodes
*
* @export
* @param {*} tree
* @param tree
* @returns
*/
export function treeNodeCount(tree) {
@@ -36,11 +36,11 @@ export function treeNodeCount(tree) {
* Recursively count the number of nodes with a method
*
* @export
* @param {*} tree
* @param tree
* @returns
*/
export function rawNodesWithMethodCount(tree) {
return tree.filter(node => {
return tree.filter((node) => {
let childHadMethod: boolean;

if (node.method) {
@@ -55,13 +55,12 @@ export function rawNodesWithMethodCount(tree) {
}).length;
}


/**
* Recursively count valid API references
* Deprecated API refs are invalid
*
* @export
* @param {*} apiList
* @param apiList
* @returns
*/
export function validApiRefCount(apiList): number {
1 change: 0 additions & 1 deletion apps/rxjs.dev/tools/transforms/.eslintignore

This file was deleted.

20 changes: 0 additions & 20 deletions apps/rxjs.dev/tools/transforms/.eslintrc.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -5,8 +5,7 @@ describe('addImageDimensions post-processor', () => {
let processor, getImageDimensionsSpy, addImageDimensions, log;

beforeEach(() => {
const testPackage = createTestPackage('angular-base-package')
.factory('getImageDimensions', mockGetImageDimensions);
const testPackage = createTestPackage('angular-base-package').factory('getImageDimensions', mockGetImageDimensions);
const dgeni = new Dgeni([testPackage]);
const injector = dgeni.configureInjector();
log = injector.get('log');
@@ -19,42 +18,50 @@ describe('addImageDimensions post-processor', () => {
});

it('should add the image dimensions into <img> tags', () => {
const docs = [{
docType: 'a',
renderedContent: `
const docs = [
{
docType: 'a',
renderedContent: `
<p>xxx</p>
<img src="a/b.jpg">
<p>yyy</p>
<img src="c/d.png">
<p>zzz</p>
`
}];
`,
},
];
processor.$process(docs);
expect(getImageDimensionsSpy).toHaveBeenCalledWith('base/path', 'a/b.jpg');
expect(getImageDimensionsSpy).toHaveBeenCalledWith('base/path', 'c/d.png');
expect(docs).toEqual([jasmine.objectContaining({
docType: 'a',
renderedContent: `
expect(docs).toEqual([
jasmine.objectContaining({
docType: 'a',
renderedContent: `
<p>xxx</p>
<img src="a/b.jpg" width="10" height="20">
<p>yyy</p>
<img src="c/d.png" width="30" height="40">
<p>zzz</p>
`
})]);
`,
}),
]);
});

it('should log a warning for images with no src attribute', () => {
const docs = [{
docType: 'a',
renderedContent: '<img attr="value">'
}];
const docs = [
{
docType: 'a',
renderedContent: '<img attr="value">',
},
];
processor.$process(docs);
expect(getImageDimensionsSpy).not.toHaveBeenCalled();
expect(docs).toEqual([jasmine.objectContaining({
docType: 'a',
renderedContent: '<img attr="value">'
})]);
expect(docs).toEqual([
jasmine.objectContaining({
docType: 'a',
renderedContent: '<img attr="value">',
}),
]);
expect(log.warn).toHaveBeenCalledWith('Missing src in image tag `<img attr="value">` - doc (a) ');
});

@@ -64,42 +71,46 @@ describe('addImageDimensions post-processor', () => {
error.code = 'ENOENT';
throw error;
});
const docs = [{
docType: 'a',
renderedContent: '<img src="missing">'
}];
const docs = [
{
docType: 'a',
renderedContent: '<img src="missing">',
},
];
processor.$process(docs);
expect(log.warn).toHaveBeenCalledWith('Unable to load src in image tag `<img src="missing">` - doc (a) ');
expect(getImageDimensionsSpy).toHaveBeenCalledWith('base/path', 'missing');
});

it('should ignore images with width or height attributes', () => {
const docs = [{
docType: 'a',
renderedContent: `
const docs = [
{
docType: 'a',
renderedContent: `
<img src="a/b.jpg" width="10">
<img src="c/d.jpg" height="10">
<img src="e/f.jpg" width="10" height="10">
`
}];
`,
},
];
processor.$process(docs);
expect(docs).toEqual([jasmine.objectContaining({
docType: 'a',
renderedContent: `
expect(docs).toEqual([
jasmine.objectContaining({
docType: 'a',
renderedContent: `
<img src="a/b.jpg" width="10">
<img src="c/d.jpg" height="10">
<img src="e/f.jpg" width="10" height="10">
`
})]);
`,
}),
]);
});

function mockGetImageDimensions() {
const imageInfo = {
'a/b.jpg': { width: 10, height: 20 },
'c/d.png': { width: 30, height: 40 },
};
// eslint-disable-next-line jasmine/no-unsafe-spy
return jasmine.createSpy('getImageDimensions')
.and.callFake((base, url) => imageInfo[url]);
return jasmine.createSpy('getImageDimensions').and.callFake((base, url) => imageInfo[url]);
}
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint jasmine/prefer-toHaveBeenCalledWith:0 */
const fs = require('fs/promises');
const { resolve } = require('canonical-path');
const { generateDocs } = require('./index.js');
103 changes: 103 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const globals = require('globals');
const js = require('@eslint/js');
const eslintrc = require('@eslint/eslintrc');
const path = require('path');
const jsdoc = require('eslint-plugin-jsdoc');
const angular = require('@angular-eslint/eslint-plugin');

const compat = new eslintrc.FlatCompat({ baseDirectory: __dirname });

// "eslint.experimental.useFlatConfig": true

module.exports = [
{ ignores: ['**/dist', '**/vite-bundle', '**/assets', 'apps/rxjs.dev/tools/transforms/**/*.template.js'] },
js.configs.recommended,
...compat.extends('plugin:@typescript-eslint/recommended'),
{
languageOptions: {
globals: {
...globals.node,
...globals.browser,
},
},
rules: {
'no-prototype-builtins': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['**/*.js', '**/*.mjs'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['**/*.ts', '**/*.mts'],
plugins: {
jsdoc,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',

'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'jsdoc/check-alignment': 'error',
'jsdoc/no-types': 'error',
},
},
{
files: ['packages/rxjs/**/*.ts', 'packages/rxjs/**/*.mts'],
languageOptions: {
parserOptions: { project: true, tsconfigRootDir: path.resolve(__dirname, './packages/rxjs') },
},
},
{
files: ['apps/rxjs.dev/**/*.spec.js'],
languageOptions: {
globals: {
...globals.jasmine,
},
},
},
{
files: ['apps/rxjs.dev/**/*.ts', 'apps/rxjs.dev/**/*.mts'],
plugins: {
'@angular-eslint': angular,
},
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: path.resolve(__dirname, './apps/rxjs.dev'),
},
},
rules: {
'@typescript-eslint/consistent-type-imports': 'off',
'@typescript-eslint/consistent-type-exports': 'off',

'@angular-eslint/component-class-suffix': 'error',
'@angular-eslint/component-selector': ['error', { prefix: 'aio', style: 'kebab-case', type: 'element' }],
'@angular-eslint/contextual-lifecycle': 'error',
'@angular-eslint/directive-class-suffix': 'error',
'@angular-eslint/directive-selector': ['error', { prefix: 'aio', style: 'camelCase', type: 'attribute' }],
'@angular-eslint/no-conflicting-lifecycle': 'error',
'@angular-eslint/no-host-metadata-property': 'off',
'@angular-eslint/no-input-rename': 'error',
'@angular-eslint/no-inputs-metadata-property': 'error',
'@angular-eslint/no-output-native': 'error',
'@angular-eslint/no-output-on-prefix': 'error',
'@angular-eslint/no-output-rename': 'error',
'@angular-eslint/no-outputs-metadata-property': 'error',
'@angular-eslint/use-lifecycle-interface': 'error',
'@angular-eslint/use-pipe-transform-interface': 'error',
},
},
{
files: ['apps/rxjs.dev/tests/e2e/**/*.e2e-spec.ts'],
languageOptions: {
parserOptions: {
project: ['tests/e2e/tsconfig.e2e.json'],
},
},
},
];
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -20,6 +20,14 @@
"packageManager": "yarn@1.22.21",
"dependencies": {},
"devDependencies": {
"@angular-eslint/eslint-plugin": "^17.1.0",
"@angular-eslint/eslint-plugin-template": "^17.1.0",
"@angular-eslint/template-parser": "^17.1.0",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"eslint": "^8.54.0",
"eslint-plugin-jsdoc": "^46.9.0",
"globals": "^13.23.0",
"lerna": "^7.3.0"
}
}
29 changes: 0 additions & 29 deletions packages/rxjs/.eslintrc.json

This file was deleted.

6 changes: 2 additions & 4 deletions packages/rxjs/package.json
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@
},
"scripts": {
"changelog": "npx conventional-changelog-cli -p angular -i CHANGELOG.md -s",
"lint": "eslint --ext=ts,js src spec spec-dtslint",
"lint": "eslint .",
"dtslint": "npm run lint && tsc -b ./src/tsconfig.types.json",
"prepublishOnly": "yarn build && yarn lint && yarn test && yarn test:circular && yarn dtslint && yarn copy_common_package_files",
"test": "yarn build && cross-env TS_NODE_PROJECT=tsconfig.mocha.json mocha --config spec/support/.mocharc.js \"spec/**/*-spec.ts\"",
@@ -143,17 +143,15 @@
"@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",
"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",
"form-data": "^3.0.0",
"fs-extra": "^8.1.0",
"globals": "^13.23.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"lodash": "^4.17.21",
4 changes: 2 additions & 2 deletions packages/rxjs/spec-dtslint/Observable-spec.ts
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ function a<I, O extends string>(output: O): OperatorFunction<I, O>;
* );
* ```
*
* @param {string} input The `OperatorFunction` input type parameter
* @param {string} output The `OperatorFunction` output type parameter
* @param input The `OperatorFunction` input type parameter
* @param output The `OperatorFunction` output type parameter
*/
function a<I, O extends string>(inputOrOutput: I | O, output?: O): OperatorFunction<I, O> {
return map(() => output === undefined ? inputOrOutput as O : output);
4 changes: 2 additions & 2 deletions packages/rxjs/spec-dtslint/util/pipe-spec.ts
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@ import { pipe, of } from 'rxjs';
* a('0', '1'), a('#', '2') // Error '1' is not compatible with '#'
* ```
*
* @param {string} input The `UnaryFunction` input type parameter
* @param {string} output The `UnaryFunction` output type parameter
* @param input The `UnaryFunction` input type parameter
* @param output The `UnaryFunction` output type parameter
*/
function a<I extends string, O extends string>(input: I, output: O): UnaryFunction<I, O> {
return i => output;
357 changes: 175 additions & 182 deletions yarn.lock

Large diffs are not rendered by default.