Skip to content

feat: introduce eslint and remove tslint closes (#374) #382

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

Merged
merged 9 commits into from
Jan 23, 2024
Merged
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
44 changes: 44 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"root": true,
"ignorePatterns": ["projects/**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates"
],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "sp",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"warn",
{
"type": "element",
"prefix": "sp",
"style": "kebab-case"
}
],
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public"
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@angular-eslint/template/recommended"],
"rules": {}
}
]
}
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: yarn
- name: Lint
run: yarn lint
- name: Run tests
run: yarn test_ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
!.vscode/extensions.json

# misc
/.nx/*
/.angular/cache
/.sass-cache
/connect.lock
Expand Down
32 changes: 29 additions & 3 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
"outputPath": "dist/angular-split-app",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": ["zone.js"],
"polyfills": [
"zone.js"
],
"tsConfig": "src/tsconfig.app.json",
"assets": ["src/favicon.ico", "src/assets"],
"styles": ["./node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.scss"],
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.scss"
],
"scripts": []
},
"configurations": {
Expand Down Expand Up @@ -60,6 +68,15 @@
"deploy": {
"builder": "angular-cli-ghpages:deploy",
"options": {}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"src/**/*.ts",
"src/**/*.html"
]
}
}
}
},
Expand All @@ -75,6 +92,15 @@
"tsConfig": "projects/angular-split/tsconfig.lib.json",
"project": "projects/angular-split/ng-package.json"
}
},
"lint": {
"builder": "@angular-eslint/builder:lint",
"options": {
"lintFilePatterns": [
"projects/angular-split/**/*.ts",
"projects/angular-split/**/*.html"
]
}
}
}
}
Expand Down
61 changes: 51 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
"lib_pub_latest": "wireit",
"lib_pub_next": "wireit",
"lib_tgz": "wireit",
"lint": "ng lint",
"lint_lib": "wireit",
"lint_app": "wireit",
"lint": "wireit",
"ng": "ng",
"start": "wireit"
"start": "wireit",
"prepare": "husky install"
},
"private": true,
"dependencies": {
Expand All @@ -39,30 +42,40 @@
"zone.js": "~0.14.2"
},
"devDependencies": {
"@angular-devkit/architect": "^0.1701.0",
"@angular-devkit/build-angular": "^17.1.0",
"@angular-devkit/core": "^17.1.0",
"@angular-devkit/schematics": "^17.1.0",
"@angular/cli": "^17.1.0",
"@angular/compiler-cli": "^17.1.0",
"@angular/language-service": "^17.1.0",
"@angular-devkit/architect": "^0.1700.0",
"@angular-devkit/build-angular": "^17.0.0",
"@angular-devkit/core": "^17.0.0",
"@angular-devkit/schematics": "^17.0.0",
"@angular-eslint/builder": "17.2.1",
"@angular-eslint/eslint-plugin": "17.2.1",
"@angular-eslint/eslint-plugin-template": "17.2.1",
"@angular-eslint/schematics": "17.2.1",
"@angular-eslint/template-parser": "17.2.1",
"@angular/cli": "^17.0.0",
"@angular/compiler-cli": "^17.0.2",
"@angular/language-service": "^17.0.2",
"@types/marked": "^5.0.1",
"@types/node": "20.5.4",
"@typescript-eslint/eslint-plugin": "6.19.0",
"@typescript-eslint/parser": "6.19.0",
"codelyzer": "^6.0.2",
"concurrently": "8.2.1",
"cypress": "12.17.4",
"eslint": "^8.56.0",
"ng-packagr": "^17.0.0",
"npm-run-all": "4.1.5",
"postcss": "8.4.28",
"serve": "^14.2.1",
"ts-node": "10.9.1",
"tslib": "^2.6.2",
"tslint": "~6.1.3",
"typescript": "5.2.2",
"webpack-bundle-analyzer": "4.9.0",
"wireit": "^0.14.3"
},
"lint-staged": {
"*.{ts,html}": [
"yarn lint -- --quiet"
],
"*.{js,json,css,scss,less,md,ts,tsx,html,component.html,graphql}": [
"prettier --write"
]
Expand All @@ -83,12 +96,29 @@
"dist/angular-split-app"
]
},
"lint_app": {
"command": "ng lint --project angular-split-app --fix",
"files": [
"**/*.ts",
"**/*.html",
".eslintignore",
".eslintrc.cjs",
".eslintrc.json"
],
"output": []
},
"build": {
"dependencies": [
"app_build",
"lib_build"
]
},
"lint": {
"dependencies": [
"lint_app",
"lint_lib"
]
},
"test_ci": {
"dependencies": [
"cypress_run",
Expand Down Expand Up @@ -136,6 +166,17 @@
"dist/angular-split"
]
},
"lint_lib": {
"command": "ng lint --project angular-split --fix",
"files": [
"**/*.ts",
"**/*.html",
".eslintignore",
".eslintrc.cjs",
".eslintrc.json"
],
"output": []
},
"lib_pub_latest": {
"command": "npm publish --tag latest ./dist/angular-split",
"dependencies": [
Expand Down
31 changes: 31 additions & 0 deletions projects/angular-split/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": "../../.eslintrc.json",
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"rules": {
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "as",
"style": "camelCase"
}
],
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "as",
"style": "kebab-case"
}
]
}
},
{
"files": ["*.html"],
"rules": {}
}
]
}
8 changes: 5 additions & 3 deletions projects/angular-split/src/lib/component/split.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export class SplitComponent implements AfterViewInit, OnDestroy {
private isDragging = false
private isWaitingClear = false
private isWaitingInitialMove = false
private dragListeners: Array<Function> = []
private dragListeners: Array<() => void> = []
private snapshot: ISplitSnapshot | null = null
private startPoint: IPoint | null = null
private endPoint: IPoint | null = null
Expand Down Expand Up @@ -414,8 +414,8 @@ export class SplitComponent implements AfterViewInit, OnDestroy {
return false
}

// @ts-ignore
this.displayedAreas.forEach((area, i) => (area.component._size = formattedSizes[i]))
// @@ts-expect-error
this.displayedAreas.forEach((area, i) => (area.component.size = formattedSizes[i]))

this.build(false, true)
return true
Expand Down Expand Up @@ -791,7 +791,9 @@ export class SplitComponent implements AfterViewInit, OnDestroy {

// Each gutter side areas can't absorb all offset
if (areasBefore.remain !== 0 && areasAfter.remain !== 0) {
// TODO: fix this emty block
if (Math.abs(areasBefore.remain) === Math.abs(areasAfter.remain)) {
/* empty */
} else if (Math.abs(areasBefore.remain) > Math.abs(areasAfter.remain)) {
areasAfter = getGutterSideAbsorptionCapacity(
this.unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getInputBoolean, getInputPositiveNumber } from '../utils'
import { IAreaSize } from '../interface'

@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: 'as-split-area, [as-split-area]',
exportAs: 'asSplitArea',
})
Expand Down Expand Up @@ -87,10 +88,10 @@ export class SplitAreaDirective implements OnInit, OnDestroy {
return this._visible
}

private transitionListener: Function
private transitionListener: () => void
private dragStartSubscription: Subscription
private dragEndSubscription: Subscription
private readonly lockListeners: Array<Function> = []
private readonly lockListeners: Array<() => void> = []

constructor(
private ngZone: NgZone,
Expand Down
20 changes: 8 additions & 12 deletions projects/angular-split/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ElementRef } from '@angular/core'
import {
IArea,
IPoint,
IAreaSnapshot,
ISplitSideAbsorptionCapacity,
IAreaAbsorptionCapacity,
IAreaSize,
IAreaSnapshot,
IPoint,
ISplitDirection,
ISplitSideAbsorptionCapacity,
ISplitUnit,
} from './interface'

Expand Down Expand Up @@ -112,11 +112,11 @@ export function getElementPixelSize(elRef: ElementRef, direction: ISplitDirectio
return direction === 'horizontal' ? rect.width : rect.height
}

export function getInputBoolean(v: any): boolean {
return typeof v === 'boolean' ? v : v === 'false' ? false : true
export function getInputBoolean(v: boolean | `${boolean}`): boolean {
return typeof v === 'boolean' ? v : v !== 'false'
}

export function getInputPositiveNumber<T>(v: any, defaultValue: T): number | T {
export function getInputPositiveNumber<T>(v: number | `${number}` | '*', defaultValue: T): number | T {
if (v === null || v === undefined) return defaultValue

v = Number(v)
Expand Down Expand Up @@ -236,7 +236,7 @@ function getAreaAbsorptionCapacity(
}

if (unit === 'pixel') {
return getAreaAbsorptionCapacityPixel(areaSnapshot, pixels, allAreasSizePixel)
return getAreaAbsorptionCapacityPixel(areaSnapshot, pixels)
}
}

Expand Down Expand Up @@ -302,11 +302,7 @@ function getAreaAbsorptionCapacityPercent(
}
}

function getAreaAbsorptionCapacityPixel(
areaSnapshot: IAreaSnapshot,
pixels: number,
containerSizePixel: number,
): IAreaAbsorptionCapacity {
function getAreaAbsorptionCapacityPixel(areaSnapshot: IAreaSnapshot, pixels: number): IAreaAbsorptionCapacity {
const tempPixelSize = areaSnapshot.sizePixelAtStart + pixels

// ENLARGE AREA
Expand Down
1 change: 1 addition & 0 deletions projects/angular-split/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'core-js/es7/reflect'
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { filter } from 'rxjs/operators'
})
export class AppComponent {
constructor(public router: Router) {
this.router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe((event) => {
this.router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe(() => {
window.scrollTo(0, 0)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/changelog/changelog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class ChangelogService {
this.cachedHtml = marked(md)
return this.cachedHtml
}),
catchError((error) =>
catchError(() =>
of(
`Error:<br>Unable to retrieve CHANGELOG.md from github..<br>Please go to <a href="${this.url}">${this.url}</a> to view it.`,
),
Expand Down
Loading