Skip to content

Commit

Permalink
add eslint (#3421)
Browse files Browse the repository at this point in the history
* add eslint

* cleanup build.ts
  • Loading branch information
robertIsaac committed Aug 29, 2023
1 parent 596e208 commit 4172abd
Show file tree
Hide file tree
Showing 140 changed files with 1,802 additions and 1,133 deletions.
20 changes: 7 additions & 13 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,17 @@
"karmaConfig": "karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.json",
"tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
}
}
}
}
},
"cli": {
"packageManager": "yarn",
"analytics": "86795b8f-9036-4a53-929c-a7303453d677"
}
}
}
109 changes: 109 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const tsParser = require('@typescript-eslint/parser');
const js = require('@eslint/js');
const globals = require('globals');
const ts = require('@typescript-eslint/eslint-plugin');
const ng = require('@angular-eslint/eslint-plugin');
const esImport = require('eslint-plugin-import');

module.exports = [
{
files: ['**/*.ts'],
plugins: {
'@typescript-eslint': ts,
'@angular-eslint': ng,
import: esImport,
},
languageOptions: {
parser: tsParser,
globals: {
...globals.browser,
},
parserOptions: {
project: ['tsconfig.build.json', 'tsconfig.json', 'tsconfig.spec.json'],
},
},
rules: {
...js.configs.recommended.rules,
...ts.configs['recommended-requiring-type-checking'].rules,
...ts.configs['stylistic-type-checked'].rules,
...ng.configs.recommended.rules,
...esImport.configs.errors.rules,
// eslint/js rules
'no-undef': 'off',
'no-redeclare': 'off',
'prefer-arrow-callback': 'error',
'curly': 'error',
'no-dupe-class-members': 'off',
"no-restricted-imports": ["error", "rxjs/Rx"],
"no-console": ["error", {allow: ['log', 'error', 'warn']}],
'sort-imports': [
'error',
{
ignoreDeclarationSort: true,
},
],
// @typescript-eslint rules
'@typescript-eslint/prefer-nullish-coalescing': 'off', // require `strictNullChecks`
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off', // causing pipeline error in src/compat/firestore/utils.spec.ts
'@typescript-eslint/no-non-null-assertion': 'error',
"@typescript-eslint/member-ordering": ["error", {
"default": [
"static-field",
"instance-field",
"static-method",
"instance-method"
]
}],
'@typescript-eslint/no-unused-vars': [
'error', {args: "after-used", "argsIgnorePattern": "^_"}
],
// @angular-eslint rules
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case',
},
],
// import rules
'import/no-unresolved': 'off',
'import/namespace': 'off',
'import/default': 'off',
'import/export': 'off',
'import/newline-after-import': 'error',
'import/order': [
'error',
{
alphabetize: {order: 'asc'},
"newlines-between": "never"
},
],
},
},
{
files: ['**/*.spec.ts'],
languageOptions: {
globals: {
...globals.jasmine,
},
},
},
];
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"test:safari": "npx --yes firebase-tools emulators:exec --project=demo123 \"ng test --watch=false --browsers=SafariNative\"",
"test:chrome-headless": "npx --yes firebase-tools emulators:exec --project=demo123 \"ng test --watch=false --browsers=ChromeHeadless\"",
"test:firefox-headless": "npx --yes firebase-tools emulators:exec --project=demo123 \"ng test --watch=false --browsers=FirefoxHeadless\"",
"lint": "echo 'todo: fix tslint -> eslint'",
"lint": "ng lint",
"test:node": "node -r tsconfig-paths/register ./dist/out-tsc/jasmine/tools/jasmine.mjs --input-type=commonjs",
"test:node-esm": "node -r tsconfig-paths/register ./dist/out-tsc/jasmine/tools/jasmine.mjs",
"test:typings": "node ./tools/run-typings-test.js",
Expand Down Expand Up @@ -77,6 +77,8 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "^16.0.0",
"@angular-eslint/builder": "^16.1.1",
"@angular-eslint/eslint-plugin": "^16.1.1",
"@angular-eslint/schematics": "16.0.3",
"@angular/animations": "~16.0.0",
"@angular/cli": "^16.0.0",
Expand All @@ -92,12 +94,17 @@
"@types/semver": "^7.1.0",
"@types/triple-beam": "^1.3.0",
"@types/winston": "^2.4.4",
"@typescript-eslint/eslint-plugin": "^6.5.0",
"@typescript-eslint/parser": "^6.5.0",
"codelyzer": "^6.0.0",
"concurrently": "^2.2.0",
"conventional-changelog-cli": "^1.2.0",
"cross-spawn": "^7.0.3",
"eslint": "^8.48.0",
"eslint-plugin-import": "^2.28.1",
"file-loader": "^6.2.0",
"firebase-functions-test": "^0.2.2",
"globals": "^13.21.0",
"globalthis": "^1.0.1",
"gzip-size": "^5.1.1",
"jasmine": "^5.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/analytics/analytics.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NgModule, Optional, NgZone, InjectionToken, ModuleWithProviders, APP_INITIALIZER, Injector } from '@angular/core';
import { APP_INITIALIZER, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional } from '@angular/core';
import { VERSION, ɵAngularFireSchedulers, ɵgetDefaultInstanceOf } from '@angular/fire';
import { FirebaseApp, FirebaseApps } from '@angular/fire/app';
import { Analytics as FirebaseAnalytics } from 'firebase/analytics';
import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, VERSION } from '@angular/fire';
import { Analytics, ANALYTICS_PROVIDER_NAME, AnalyticsInstances } from './analytics';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { ANALYTICS_PROVIDER_NAME, Analytics, AnalyticsInstances } from './analytics';
import { isAnalyticsSupportedFactory } from './is-analytics-supported-factory';
import { ScreenTrackingService } from './screen-tracking.service';
import { UserTrackingService } from './user-tracking.service';
import { isAnalyticsSupportedFactory } from './is-analytics-supported-factory';

export const PROVIDED_ANALYTICS_INSTANCES = new InjectionToken<Analytics[]>('angularfire2.analytics-instances');

Expand Down
4 changes: 2 additions & 2 deletions src/analytics/analytics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp, deleteApp } from '@angular/fire/app';
import { Analytics, provideAnalytics, getAnalytics, isSupported } from '@angular/fire/analytics';
import { Analytics, getAnalytics, isSupported, provideAnalytics } from '@angular/fire/analytics';
import { FirebaseApp, getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { COMMON_CONFIG_TOO } from '../test-config';
import { rando } from '../utils';

Expand Down
6 changes: 3 additions & 3 deletions src/analytics/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Analytics as FirebaseAnalytics } from 'firebase/analytics';
import { ɵgetAllInstancesOf } from '@angular/fire';
import { Analytics as FirebaseAnalytics } from 'firebase/analytics';
import { from, timer } from 'rxjs';
import { concatMap, distinct } from 'rxjs/operators';

// see notes in core/firebase.app.module.ts for why we're building the class like this
// tslint:disable-next-line:no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Analytics extends FirebaseAnalytics {}

export class Analytics {
Expand All @@ -15,7 +15,7 @@ export class Analytics {

export const ANALYTICS_PROVIDER_NAME = 'analytics';

// tslint:disable-next-line:no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AnalyticsInstances extends Array<FirebaseAnalytics> {}

export class AnalyticsInstances {
Expand Down
4 changes: 2 additions & 2 deletions src/analytics/firebase.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/analytics/screen-tracking.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { ComponentFactoryResolver, Injectable, NgZone, OnDestroy, Optional, Injector } from '@angular/core';
import { of, Subscription, Observable } from 'rxjs';
import { distinctUntilChanged, filter, groupBy, map, mergeMap, pairwise, startWith, switchMap } from 'rxjs/operators';
import { ActivationEnd, Router, ɵEmptyOutletComponent } from '@angular/router';
import { Title } from '@angular/platform-browser';
import { ComponentFactoryResolver, Injectable, Injector, NgZone, OnDestroy, Optional } from '@angular/core';
import { VERSION } from '@angular/fire';
import { Title } from '@angular/platform-browser';
import { ActivationEnd, Router, ɵEmptyOutletComponent } from '@angular/router';
import { registerVersion } from 'firebase/app';

import { Observable, Subscription, of } from 'rxjs';
import { distinctUntilChanged, filter, groupBy, map, mergeMap, pairwise, startWith, switchMap } from 'rxjs/operators';
import { Analytics } from './analytics';
import { logEvent, isSupported } from './firebase';
import { isSupported, logEvent } from './firebase';
import { UserTrackingService } from './user-tracking.service';

const FIREBASE_EVENT_ORIGIN_KEY = 'firebase_event_origin';
Expand All @@ -29,14 +28,15 @@ const SCREEN_INSTANCE_DELIMITER = '#';
// this is an INT64 in iOS/Android but use INT32 cause javascript
let nextScreenInstanceID = Math.floor(Math.random() * (2 ** 32 - 1)) - 2 ** 31;

const knownScreenInstanceIDs: { [key: string]: number } = {};
const knownScreenInstanceIDs: Record<string, number> = {};

const getScreenInstanceID = (params: { [key: string]: any }) => {
const getScreenInstanceID = (params: Record<string, any>) => {
// unique the screen class against the outlet name
const screenInstanceKey = [
params[SCREEN_CLASS_KEY],
params[OUTLET_KEY]
].join(SCREEN_INSTANCE_DELIMITER);
// eslint-disable-next-line no-prototype-builtins
if (knownScreenInstanceIDs.hasOwnProperty(screenInstanceKey)) {
return knownScreenInstanceIDs[screenInstanceKey];
} else {
Expand Down
7 changes: 3 additions & 4 deletions src/analytics/user-tracking.service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import { Injectable, Injector, NgZone, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { VERSION } from '@angular/fire';
import { Auth, authState } from '@angular/fire/auth';
import { registerVersion } from 'firebase/app';

import { Subscription } from 'rxjs';
import { Analytics } from './analytics';
import { setUserId, isSupported } from './firebase';
import { isSupported, setUserId } from './firebase';

@Injectable()
export class UserTrackingService implements OnDestroy {

public readonly initialized: Promise<void>;
private disposables: Array<Subscription> = [];
private disposables: Subscription[] = [];

constructor(
auth: Auth,
Expand Down
13 changes: 6 additions & 7 deletions src/app-check/app-check.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NgModule, Optional, NgZone, InjectionToken, ModuleWithProviders, PLATFORM_ID, isDevMode, Injector } from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, Optional, PLATFORM_ID, isDevMode } from '@angular/core';
import { VERSION, ɵAPP_CHECK_PROVIDER_NAME, ɵAngularFireSchedulers, ɵAppCheckInstances, ɵgetDefaultInstanceOf } from '@angular/fire';
import { FirebaseApp, FirebaseApps } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { AppCheck as FirebaseAppCheck } from 'firebase/app-check';
import { ɵgetDefaultInstanceOf, ɵAngularFireSchedulers, ɵAppCheckInstances, ɵAPP_CHECK_PROVIDER_NAME, VERSION } from '@angular/fire';
import { AppCheck } from './app-check';
import { FirebaseApps, FirebaseApp } from '@angular/fire/app';
import { registerVersion } from 'firebase/app';
import { isPlatformServer } from '@angular/common';

export const PROVIDED_APP_CHECK_INSTANCES = new InjectionToken<AppCheck[]>('angularfire2.app-check-instances');

Expand All @@ -17,8 +17,7 @@ const LOCALHOSTS = ['localhost', '0.0.0.0', '127.0.0.1'];
const isLocalhost = typeof window !== 'undefined' && LOCALHOSTS.includes(window.location.hostname);

export function appCheckInstanceFactory(fn: (injector: Injector) => FirebaseAppCheck) {
// tslint:disable-next-line:ban-types
return (zone: NgZone, injector: Injector, platformId: Object) => {
return (zone: NgZone, injector: Injector, platformId: unknown) => {
// Node should use admin token provider, browser devmode and localhost should use debug token
if (!isPlatformServer(platformId) && (isDevMode() || isLocalhost)) {
globalThis.FIREBASE_APPCHECK_DEBUG_TOKEN ??= true;
Expand Down
4 changes: 2 additions & 2 deletions src/app-check/app-check.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { FirebaseApp, provideFirebaseApp, getApp, initializeApp, deleteApp } from '@angular/fire/app';
import { Auth, provideAuth, getAuth, connectAuthEmulator } from '@angular/fire/auth';
import { FirebaseApp, getApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { Auth, connectAuthEmulator, getAuth, provideAuth } from '@angular/fire/auth';
import { COMMON_CONFIG } from '../test-config';
import { rando } from '../utils';

Expand Down
4 changes: 2 additions & 2 deletions src/app-check/app-check.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ɵAPP_CHECK_PROVIDER_NAME, ɵgetAllInstancesOf } from '@angular/fire';
import { AppCheck as FirebaseAppCheck } from 'firebase/app-check';
import { ɵgetAllInstancesOf, ɵAPP_CHECK_PROVIDER_NAME } from '@angular/fire';
import { from, timer } from 'rxjs';
import { concatMap, distinct } from 'rxjs/operators';

// see notes in core/firebase.app.module.ts for why we're building the class like this
// tslint:disable-next-line:no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AppCheck extends FirebaseAppCheck {}

export class AppCheck {
Expand Down
10 changes: 5 additions & 5 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import {
InjectionToken,
Injector,
ModuleWithProviders,
VERSION as NG_VERSION,
NgModule,
NgZone,
Optional,
PLATFORM_ID,
VERSION as NG_VERSION,
} from '@angular/core';
import { VERSION, ɵAngularFireSchedulers } from '@angular/fire';
import { FirebaseApp as IFirebaseApp, getApp, registerVersion } from 'firebase/app';

import { FirebaseApp, FirebaseApps } from './app';
import { VERSION, ɵAngularFireSchedulers } from '@angular/fire';

export function defaultFirebaseAppFactory(provided: FirebaseApp[]|undefined) {
// Use the provided app, if there is only one, otherwise fetch the default app
Expand All @@ -23,7 +22,7 @@ export function defaultFirebaseAppFactory(provided: FirebaseApp[]|undefined) {
// With FIREBASE_APPS I wanted to capture the default app instance, if it is initialized by
// the reserved URL; ɵPROVIDED_FIREBASE_APPS is not for public consumption and serves to ensure that all
// provideFirebaseApp(...) calls are satisfied before FirebaseApp$ or FirebaseApp is resolved
export const PROVIDED_FIREBASE_APPS = new InjectionToken<Array<FirebaseApp>>('angularfire2._apps');
export const PROVIDED_FIREBASE_APPS = new InjectionToken<FirebaseApp[]>('angularfire2._apps');

// Injecting FirebaseApp will now only inject the default Firebase App
// this allows allows beginners to import /__/firebase/init.js to auto initialize Firebase App
Expand Down Expand Up @@ -57,10 +56,11 @@ export function firebaseAppFactory(fn: (injector: Injector) => IFirebaseApp) {
]
})
export class FirebaseAppModule {
// tslint:disable-next-line:ban-types
// eslint-disable-next-line @typescript-eslint/ban-types
constructor(@Inject(PLATFORM_ID) platformId: Object) {
registerVersion('angularfire', VERSION.full, 'core');
registerVersion('angularfire', VERSION.full, 'app');
// eslint-disable-next-line @typescript-eslint/no-base-to-string
registerVersion('angular', NG_VERSION.full, platformId.toString());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing';
import { FirebaseApp, provideFirebaseApp, initializeApp, deleteApp } from '@angular/fire/app';
import { FirebaseApp, initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { COMMON_CONFIG } from '../test-config';
import { rando } from '../utils';

Expand Down

0 comments on commit 4172abd

Please sign in to comment.