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

feat: Deprecate from chectl tslint and add eslint with check license headers #1280

Merged
merged 6 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
*
flacatus marked this conversation as resolved.
Show resolved Hide resolved
* Copyright (c) 2019-2021 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: [
'./configs/eslint.json'
],
ignorePatterns: [
'**/{node_modules,lib}'
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'tsconfig.json',
sourceType: "module",
ecmaVersion: 2015,
}
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ tsconfig.tsbuildinfo
oclif.manifest.json
# templates are added at post-install step
templates
.eslintcache
23 changes: 23 additions & 0 deletions configs/base.eslint.chectl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6,
"ecmaFeatures": {
"jsx": false
}
},
"plugins": [
"@typescript-eslint",
"no-null"
],
"env": {
"browser": true,
"mocha": true,
"node": true
},
"ignorePatterns": [
"node_modules",
"lib"
]
}
30 changes: 30 additions & 0 deletions configs/disabled.rules.chectl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"plugins": ["@typescript-eslint"],
"rules": {
"no-use-before-define": 0,
"valid-jsdoc": 0,
"camelcase": 0,
"unicorn/catch-error-name": 0,
"node/no-unsupported-features/node-builtins": 0,
"no-await-in-loop": 0,
"no-mixed-operators": 0,
"max-statements-per-line": 0,
"no-negated-condition": 0,
"unicorn/explicit-length-check": 0,
"new-cap": 0,
"require-atomic-updates": 0,
"@typescript-eslint/no-empty-function": 0,
"no-useless-escape": 0,
"object-curly-spacing": 0,
"@typescript-eslint/explicit-module-boundary-types": 0,
"no-inner-declarations": 0,
"@typescript-eslint/ban-types": 0,
"no-multi-assign": 0,
"no-lonely-if": 0,
"no-async-promise-executor": 0,
"prefer-promise-reject-errors": 0,
"no-else-return": 0,
"no-useless-return": 0,
"complexity": 0
}
}
9 changes: 9 additions & 0 deletions configs/eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": [
"oclif",
"oclif-typescript",
"./eslint.license.json",
"./base.eslint.chectl.json",
"./disabled.rules.chectl.json"
]
}
25 changes: 25 additions & 0 deletions configs/eslint.license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"plugins": ["@typescript-eslint", "header"],
"rules": {
"header/header": [
2,
"block",
[
"*",
{
"pattern": "^ \\* Copyright \\(c\\) \\d{4}(-\\d{4})* Red Hat, Inc\\.$",
"template": " * Copyright (c) 2019-2021 Red Hat, Inc."
},
" * This program and the accompanying materials are made",
" * available under the terms of the Eclipse Public License 2.0",
" * which is available at https://www.eclipse.org/legal/epl-2.0/",
" *",
" * SPDX-License-Identifier: EPL-2.0",
" *",
" * Contributors:",
" * Red Hat, Inc. - initial API and implementation",
" "
]
]
}
}
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@eclipse-che/api": "latest",
"@oclif/dev-cli": "^1",
"@oclif/test": "^1",
"@oclif/tslint": "^3",
"@types/chai": "^4",
"@types/command-exists": "^1.2.0",
"@types/countries-and-timezones": "^2.0.3",
Expand All @@ -73,19 +72,25 @@
"@types/uuid": "^8.3.0",
"@types/websocket": "^1.0.1",
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"chai": "^4.2.0",
"cpx": "^1.5.0",
"eslint": "^7.28.0",
"eslint-config-oclif": "^3.1.0",
"eslint-config-oclif-typescript": "^0.2.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-no-null": "^1.0.2",
"globby": "^11",
"jest": "^26.6.3",
"nock": "^11.7.0",
"ts-jest": "^26.5.1",
"ts-node": "^9",
"tslint": "^6",
"typescript": "^4.1",
"typescript-formatter": "7.2.2"
},
"engines": {
"node": ">=8.0.0"
"node": ">=12.0.0"
},
"files": [
"/bin",
Expand Down Expand Up @@ -146,26 +151,26 @@
},
"repository": "che-incubator/chectl",
"scripts": {
"postinstall": "npm run -s postinstall-repositories && npm run -s postinstall-helm && npm run -s postinstall-cert-manager && npm run -s postinstall-operator && npm run -s postinstall-dev-workspace && npm run -s postinstall-cleanup",
"postinstall": "yarn lint && npm run -s postinstall-repositories && npm run -s postinstall-helm && npm run -s postinstall-cert-manager && npm run -s postinstall-operator && npm run -s postinstall-dev-workspace && npm run -s postinstall-cleanup",
flacatus marked this conversation as resolved.
Show resolved Hide resolved
"postinstall-helm": "rimraf templates/kubernetes && cpx 'node_modules/eclipse-che-server/deploy/kubernetes/**' 'templates/kubernetes'",
"postinstall-cert-manager": "rimraf templates/cert-manager && cpx 'node_modules/eclipse-che-server/deploy/cert-manager/**' 'templates/cert-manager'",
"postinstall-dev-workspace": "rimraf templates/devworkspace && cpx 'node_modules/eclipse-che-devfile-workspace-operator/deploy/**' 'templates/devworkspace'",
"postinstall-operator": "rimraf templates/che-operator && cpx 'node_modules/eclipse-che-operator/deploy/**' 'templates/che-operator'",
"postinstall-repositories": "yarn upgrade eclipse-che-server eclipse-che-operator eclipse-che-devfile-workspace-operator",
"postinstall-cleanup": "rimraf node_modules/eclipse-che-server && rimraf node_modules/eclipse-che-operator",
"test": "jest --collect-coverage",
"posttest": "tslint -p test -t stylish",
"test-watch": "jest --watchAll",
"e2e-minikube-helm": "export PLATFORM=minikube && export INSTALLER=helm && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"e2e-minikube-operator": "export PLATFORM=minikube && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"e2e-minishift": "export PLATFORM=minishift && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"e2e-openshift": "export PLATFORM=openshift && export INSTALLER=operator && yarn jest ./test/e2e/e2e.test.ts --testRegex='/test/(e2e)/.*.test.ts'",
"gnirts-ci": "node .ci/obfuscate/gnirts.js",
"prepack": "rm -rf lib && rm -rf tsconfig.tsbuildinfo && tsc -b && oclif-dev manifest && oclif-dev readme && yarn gnirts-ci",
"prepack": "yarn lint && rm -rf lib && rm -rf tsconfig.tsbuildinfo && tsc -b && oclif-dev manifest && oclif-dev readme && yarn gnirts-ci",
"pack-binaries": "oclif-dev pack",
"postpack": "rm -f oclif.manifest.json",
"format": "tsfmt -r --useTsfmt tsfmt.json",
"tslint-fix": "tslint --fix -p test -t stylish",
"lint": "eslint --cache=true --no-error-on-unmatched-pattern=true '{src,tests}/**/*.ts'",
"lint:fix": "eslint --fix --cache=true --no-error-on-unmatched-pattern=true \"{src,tests}/**/*.{ts,tsx}\"",
"version": "oclif-dev readme && git add README.md",
"watch": "tsc --watch"
},
Expand Down
16 changes: 9 additions & 7 deletions src/api/che-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*********************************************************************
* Copyright (c) 2019-2020 Red Hat, Inc.
*
/**
* Copyright (c) 2019-2021 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import { che as chetypes } from '@eclipse-che/api'
import axios, { AxiosInstance } from 'axios'
Expand All @@ -21,6 +23,7 @@ import { newError, sleep } from '../util'
let instance: CheApiClient | undefined
export class CheApiClient {
public defaultCheResponseTimeoutMs = 3000

public readonly cheApiEndpoint: string

private readonly axios: AxiosInstance
Expand All @@ -32,7 +35,7 @@ export class CheApiClient {
const httpsAgent = new https.Agent({ rejectUnauthorized: false })

this.axios = axios.create({
httpsAgent
httpsAgent,
})
}

Expand Down Expand Up @@ -124,7 +127,7 @@ export class CheApiClient {
async waitUntilCheServerReadyToShutdown(intervalMs = 500, timeoutMs = 60000): Promise<void> {
const iterations = timeoutMs / intervalMs
for (let index = 0; index < iterations; index++) {
let status = await this.getCheServerStatus()
const status = await this.getCheServerStatus()
if (status === 'READY_TO_SHUTDOWN') {
return
}
Expand Down Expand Up @@ -356,7 +359,6 @@ export class CheApiClient {
// that falls out of the range of 2xx
return newError(`E_CHE_API_UNKNOWN_ERROR - Endpoint: ${endpoint} -Status: ${error.response.status}`, error)
}

} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
Expand Down
34 changes: 19 additions & 15 deletions src/api/che-login-manager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*********************************************************************
* Copyright (c) 2020 Red Hat, Inc.
*
/**
* Copyright (c) 2019-2021 Red Hat, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be 2020-2021?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Old files should be 2019-2021
New files 2021-2021?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file was changed automatically by eslint

* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

import axios, { AxiosInstance } from 'axios'
import * as fs from 'fs-extra'
Expand Down Expand Up @@ -63,15 +65,15 @@ export interface PasswordLoginRecord {
}

export function isRefreshTokenLoginData(loginData: LoginRecord): loginData is RefreshTokenLoginRecord {
return !!(loginData as RefreshTokenLoginRecord).refreshToken
return Boolean((loginData as RefreshTokenLoginRecord).refreshToken)
}

export function isOcUserTokenLoginData(loginData: LoginRecord): loginData is OcUserTokenLoginRecord {
return !!(loginData as OcUserTokenLoginRecord).subjectToken
return Boolean((loginData as OcUserTokenLoginRecord).subjectToken)
}

export function isPasswordLoginData(loginData: LoginRecord): loginData is PasswordLoginRecord {
return !!(loginData as PasswordLoginRecord).password
return Boolean((loginData as PasswordLoginRecord).password)
}

// Response structure from <che-host>/api/keycloak/settings
Expand Down Expand Up @@ -115,10 +117,13 @@ let loginContext: CheServerLoginManager | undefined
*/
export class CheServerLoginManager {
private loginData: CheServerLoginConfig

private apiUrl: string

private username: string

private readonly dataFilePath: string

private readonly axios: AxiosInstance

private constructor(dataFilePath: string) {
Expand All @@ -135,7 +140,7 @@ export class CheServerLoginManager {
// Make axios ignore untrusted certificate error for self-signed certificate case.
const httpsAgent = new https.Agent({ rejectUnauthorized: false })
this.axios = axios.create({
httpsAgent
httpsAgent,
})
}

Expand Down Expand Up @@ -166,9 +171,9 @@ export class CheServerLoginManager {
public hasLoginFor(apiUrl: string, username?: string): boolean {
apiUrl = CheApiClient.normalizeCheApiEndpointUrl(apiUrl)
if (username) {
return !!this.getLoginRecord(apiUrl, username)
return Boolean(this.getLoginRecord(apiUrl, username))
} else {
return !!this.loginData.logins![apiUrl]
return Boolean(this.loginData.logins![apiUrl])
}
}

Expand All @@ -185,7 +190,7 @@ export class CheServerLoginManager {

const allLogins = new Map<string, string[]>()
for (const [apiUrl, serverLogins] of Object.entries(this.loginData.logins!)) {
allLogins.set(apiUrl, Array.from(Object.keys(serverLogins)))
allLogins.set(apiUrl, [...Object.keys(serverLogins)])
flacatus marked this conversation as resolved.
Show resolved Hide resolved
}
return allLogins
}
Expand All @@ -212,7 +217,7 @@ export class CheServerLoginManager {
}
const refreshTokenLoginRecord: RefreshTokenLoginRecord = {
refreshToken: keycloakAuthData.refresh_token,
expires: now + refreshTokenExpiresIn
expires: now + refreshTokenExpiresIn,
}

const username = isPasswordLoginData(loginRecord) ? loginRecord.username :
Expand Down Expand Up @@ -449,7 +454,7 @@ export class CheServerLoginManager {
password,
}
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
}
try {
const response = await this.axios.post(keycloakTokenUrl, querystring.stringify(data), { headers, timeout: REQUEST_TIMEOUT_MS })
Expand Down Expand Up @@ -487,7 +492,7 @@ export class CheServerLoginManager {

private async requestKeycloakAuth(keycloakTokenUrl: string, requestData: any): Promise<KeycloakAuthTokenResponse> {
const headers = {
'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'application/x-www-form-urlencoded',
}
try {
const response = await this.axios.post(keycloakTokenUrl, querystring.stringify(requestData), { headers, timeout: REQUEST_TIMEOUT_MS })
Expand Down Expand Up @@ -520,7 +525,6 @@ export class CheServerLoginManager {
throw new Error(`Failed to get userdata from ${endpoint}. Cause: ${error.message}`)
}
}

}

/**
Expand Down
Loading