Skip to content

Commit

Permalink
updated typescript eslint package (salto-io#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
alonstern authored and roironn committed May 19, 2021
1 parent a593594 commit 0b5f25a
Show file tree
Hide file tree
Showing 167 changed files with 688 additions and 606 deletions.
14 changes: 14 additions & 0 deletions eslintrc.js
Expand Up @@ -110,6 +110,20 @@ module.exports = {
'import/no-extraneous-dependencies': ['error', {
devDependencies: ['!test/**/*'],
}],
'no-shadow': ['off'],
'@typescript-eslint/no-shadow': ['error'],
'@typescript-eslint/ban-types': [
'error',
{
'extendDefaults': true,
'types': {
'{}': false,
'object': false
}
}
],
// This rule is already enforced on all functions so no need to enforce it in addition on module boundary
'@typescript-eslint/explicit-module-boundary-types': ['off'],
'jest/valid-describe': ['off'],
'import/extensions': [ 'error', 'never', {
'json': 'always',
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-api/package.json
Expand Up @@ -41,8 +41,8 @@
"@types/shelljs": "^0.7.8",
"@types/supertest": "^2.0.4",
"@types/wu": "^2.1.40",
"@typescript-eslint/eslint-plugin": "2.31.0",
"@typescript-eslint/parser": "2.31.0",
"@typescript-eslint/eslint-plugin": "4.22.1",
"@typescript-eslint/parser": "4.22.1",
"eslint": "^6.2.2",
"eslint-config-airbnb": "18.0.1",
"eslint-plugin-header": "^3.0.0",
Expand Down
23 changes: 13 additions & 10 deletions packages/adapter-api/src/adapter.ts
Expand Up @@ -58,6 +58,13 @@ export type PostFetchOptions = {
}


export type ChangeError = SaltoElementError & {
detailedMessage: string
}

export type ChangeValidator = (changes: ReadonlyArray<Change>) =>
Promise<ReadonlyArray<ChangeError>>

export type DeployModifiers = {
changeValidator?: ChangeValidator
dependencyChanger?: DependencyChanger
Expand All @@ -73,27 +80,26 @@ export type AdapterOperations = {

export type AdapterOperationName = keyof AdapterOperations

export type ServiceIds = Record<string, string>

export type ElemIdGetter = (adapterName: string, serviceIds: ServiceIds, name: string) => ElemID

export type AdapterOperationsContext = {
credentials: InstanceElement
config?: InstanceElement
getElemIdFunc?: ElemIdGetter
elementsSource: ReadOnlyElementsSource
}

export type ChangeError = SaltoElementError & {
detailedMessage: string
}

export type ChangeValidator = (changes: ReadonlyArray<Change>) =>
Promise<ReadonlyArray<ChangeError>>

export type AdapterSuccessInstallResult = { success: true; installedVersion: string }
export type AdapterFailureInstallResult = { success: false; errors: string[] }
export type AdapterInstallResult = AdapterSuccessInstallResult | AdapterFailureInstallResult

export const isAdapterSuccessInstallResult = (result: AdapterInstallResult):
result is AdapterSuccessInstallResult => result.success

export type AccountId = string

export type Adapter = {
operations: (context: AdapterOperationsContext) => AdapterOperations
validateCredentials: (config: Readonly<InstanceElement>) => Promise<AccountId>
Expand All @@ -107,8 +113,5 @@ export const ADAPTER = 'adapter'
export const OBJECT_NAME = 'object_name'
export const FIELD_NAME = 'field_name'
export const INSTANCE_NAME = 'instance_name'
export type ServiceIds = Record<string, string>
export const toServiceIdsString = (serviceIds: ServiceIds): string =>
Object.entries(serviceIds).sort().toString()
export type ElemIdGetter = (adapterName: string, serviceIds: ServiceIds, name: string) => ElemID
export type AccountId = string
9 changes: 5 additions & 4 deletions packages/adapter-api/src/authentication_types.ts
Expand Up @@ -25,6 +25,11 @@ export type AuthMethod = {
credentialsType: ObjectType
}

export type OauthAccessTokenResponse = {
instanceUrl: string
accessToken: string
}

export type OAuthMethod = AuthMethod & {
oauthRequestParameters: ObjectType
createOAuthRequest: (userInput: InstanceElement) => OAuthRequestParameters
Expand All @@ -36,9 +41,5 @@ export type AdapterAuthentication = {
oauth?: OAuthMethod
}

export type OauthAccessTokenResponse = {
instanceUrl: string
accessToken: string
}

export type AdapterAuthMethod = keyof AdapterAuthentication
3 changes: 2 additions & 1 deletion packages/adapter-api/src/builtins.ts
Expand Up @@ -53,7 +53,7 @@ const StandardBuiltinTypes = {
const restrictionType = new ObjectType({
elemID: new ElemID('', 'restriction'),
fields: {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
enforce_value: {
refType: new ReferenceExpression(
StandardBuiltinTypes.BOOLEAN.elemID,
Expand Down Expand Up @@ -88,6 +88,7 @@ const restrictionType = new ObjectType({
})

type RestrictionAnnotationType = Partial<{
// eslint-disable-next-line camelcase
enforce_value: boolean
values: ReadonlyArray<unknown>
min: number
Expand Down
20 changes: 11 additions & 9 deletions packages/adapter-api/src/elements.ts
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable no-use-before-define */

import _ from 'lodash'
import { collections, promises } from '@salto-io/lowerdash'

Expand Down Expand Up @@ -97,7 +99,7 @@ export abstract class Element {
refType => (refType.getResolvedValue(elementsSource))
)

// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
const nonTypeVals = Object.values(annotationTypes).filter(type => !isType(type))
if (nonTypeVals.length) {
throw new Error(`Element with ElemID ${this.elemID.getFullName()}'s has annotationType that resolves as non-TypeElement`)
Expand Down Expand Up @@ -152,7 +154,7 @@ abstract class PlaceholderTypeElement extends Element {

async getType(elementsSource?: ReadOnlyElementsSource): Promise<TypeElement> {
const type = await getRefTypeValue(this.refType, elementsSource)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
if (!isType(type)) {
throw new Error(`Element with ElemID ${this.elemID.getFullName()}'s type is resolved non-TypeElement`)
}
Expand All @@ -174,7 +176,7 @@ export class ListType extends Element {

isEqual(other: ListType): boolean {
return super.isEqual(other)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
&& this.refInnerType.elemID.isEqual(other.refInnerType.elemID) && isListType(other)
}

Expand All @@ -186,7 +188,7 @@ export class ListType extends Element {

async getInnerType(elementsSource?: ReadOnlyElementsSource): Promise<TypeElement> {
const refInnerTypeVal = await getRefTypeValue(this.refInnerType, elementsSource)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
if (!isType(refInnerTypeVal)) {
throw new Error(`Element with ElemID ${this.elemID.getFullName()}'s innerType is resolved non-TypeElement`)
}
Expand All @@ -197,7 +199,7 @@ export class ListType extends Element {
if (innerTypeOrRefInnerType.elemID.isEqual(this.refInnerType.elemID)) {
this.refInnerType = getRefType(innerTypeOrRefInnerType)
const innerType = this.refInnerType.value
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
if (innerType !== undefined && isType(innerType)) {
this.annotations = innerType.annotations
this.annotationRefTypes = innerType.annotationRefTypes
Expand Down Expand Up @@ -225,7 +227,7 @@ export class MapType extends Element {

isEqual(other: MapType): boolean {
return super.isEqual(other)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
&& this.refInnerType.elemID.isEqual(other.refInnerType.elemID) && isMapType(other)
}

Expand All @@ -237,7 +239,7 @@ export class MapType extends Element {

async getInnerType(elementsSource?: ReadOnlyElementsSource): Promise<TypeElement> {
const refInnerTypeVal = await getRefTypeValue(this.refInnerType, elementsSource)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
if (!isType(refInnerTypeVal)) {
throw new Error(`Element with ElemID ${this.elemID.getFullName()}'s innerType is resolved non-TypeElement`)
}
Expand All @@ -248,7 +250,7 @@ export class MapType extends Element {
if (innerTypeOrRefInnerType.elemID.isEqual(this.refInnerType.elemID)) {
this.refInnerType = getRefType(innerTypeOrRefInnerType)
const innerType = this.refInnerType.value
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
if (innerType !== undefined && isType(innerType)) {
this.annotations = innerType.annotations
this.annotationRefTypes = innerType.annotationRefTypes
Expand Down Expand Up @@ -437,7 +439,7 @@ export class InstanceElement extends PlaceholderTypeElement {

async getType(elementsSource?: ReadOnlyElementsSource): Promise<ObjectType> {
const type = await getRefTypeValue(this.refType, elementsSource)
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
if (!isObjectType(type)) {
throw new Error(`Element with ElemID ${this.elemID.getFullName()}'s type is resolved non-ObjectType`)
}
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-api/src/values.ts
Expand Up @@ -142,6 +142,7 @@ export class VariableExpression extends ReferenceExpression {
}
}

// eslint-disable-next-line no-use-before-define
export class TemplateExpression extends types.Bean<{ parts: TemplatePart[] }> { }

export type Expression = ReferenceExpression | TemplateExpression
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-api/test/elements.test.ts
Expand Up @@ -47,9 +47,9 @@ describe('Test elements.ts', () => {
const ot = new ObjectType({
elemID: otID,
fields: {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
num_field: { refType: new ReferenceExpression(primNum.elemID, primNum) },
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
str_field: { refType: new ReferenceExpression(primStr.elemID, primStr) },
},
annotationRefsOrTypes: {},
Expand Down Expand Up @@ -109,9 +109,9 @@ describe('Test elements.ts', () => {
const obj = new ObjectType({
elemID: otID,
fields: {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
num_field: { refType: new ReferenceExpression(primNum.elemID, primNum) },
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
str_field: { refType: new ReferenceExpression(primStr.elemID, primStr) },
},
annotationRefsOrTypes: {},
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-components/package.json
Expand Up @@ -48,9 +48,9 @@
"@types/shelljs": "^0.7.8",
"@types/supertest": "^2.0.4",
"@types/wu": "^2.1.40",
"@typescript-eslint/eslint-plugin": "2.31.0",
"@typescript-eslint/parser": "2.31.0",
"@types/sax": "^1.2.1",
"@typescript-eslint/eslint-plugin": "4.22.1",
"@typescript-eslint/parser": "4.22.1",
"axios-mock-adapter": "^1.19.0",
"eslint": "^6.2.2",
"eslint-config-airbnb": "18.0.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/adapter-components/src/auth/oauth.ts
Expand Up @@ -59,11 +59,11 @@ export const oauthClientCredentialsBearerToken = async ({
const res = await httpClient.post(
endpoint,
qs.stringify({
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
client_id: clientId,
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
client_secret: clientSecret,
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
grant_type: 'client_credentials',
}),
)
Expand Down
Expand Up @@ -60,7 +60,7 @@ const generateNestedType = ({
const name = toNestedTypeName(parentName, typeName)
if (validEntries.length > 0) {
if (validEntries.every(entry => Array.isArray(entry))) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
const nestedType = generateNestedType({
adapterName,
typeName,
Expand All @@ -79,7 +79,7 @@ const generateNestedType = ({
}

if (validEntries.every(entry => _.isObjectLike(entry))) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
return generateType({
adapterName,
name,
Expand Down
Expand Up @@ -63,7 +63,7 @@ const extractStandaloneFields = async (
parent: InstanceElement
objType: ObjectType
}): Promise<ReferenceExpression[]> => {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
const refInstances = await generateInstancesForType({
entries: values,
objType,
Expand Down
Expand Up @@ -77,7 +77,7 @@ const typeAdder = ({
): ObjectType | ListType | PrimitiveType => {
if (!isReferenceObject(schemaDef)) {
if (isArraySchemaObject(schemaDef)) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
return new ListType(addType(
schemaDef.items,
nestedName,
Expand All @@ -94,7 +94,7 @@ const typeAdder = ({
return BuiltinTypes.UNKNOWN
}
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
// eslint-disable-next-line no-use-before-define
return addType(
schemaDef,
nestedName,
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-components/test/auth/oauth.test.ts
Expand Up @@ -32,7 +32,7 @@ describe('oauth', () => {
mockAxiosAdapter.onPost(
'/oauth/token',
).reply(200, {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
access_token: 'token123', expires_in: 3599, token_type: 'bearer', scope: 'abc def',
})

Expand Down Expand Up @@ -68,7 +68,7 @@ describe('oauth', () => {
mockAxiosAdapter.onPost(
'/oauth/token',
).reply(200, {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
access_token: 'token123', expires_in: 3599, token_type: 'mac', scope: 'abc def',
})

Expand All @@ -85,7 +85,7 @@ describe('oauth', () => {
).reply(503).onPost(
'/oauth/token',
).reply(200, {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
access_token: 'token123', expires_in: 3599, token_type: 'bearer', scope: 'abc def',
})

Expand All @@ -100,7 +100,7 @@ describe('oauth', () => {
mockAxiosAdapter.onPost(
'/custom_oauth_endpoint',
).reply(200, {
// eslint-disable-next-line @typescript-eslint/camelcase
// eslint-disable-next-line camelcase
access_token: 'token123', expires_in: 3599, token_type: 'bearer', scope: 'abc def',
})

Expand Down
Expand Up @@ -20,7 +20,7 @@ import { createRefToElmWithValue } from '@salto-io/adapter-utils'
import { toInstance } from '../../../src/elements/ducktype'
import { RECORDS_PATH } from '../../../src/elements/constants'

/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable camelcase */
const ADAPTER_NAME = 'myAdapter'

const type = new ObjectType({
Expand Down
Expand Up @@ -19,7 +19,7 @@ import { createRefToElmWithValue } from '@salto-io/adapter-utils'
import { generateType, toNestedTypeName } from '../../../src/elements/ducktype'
import { TYPES_PATH, SUBTYPES_PATH } from '../../../src/elements'

/* eslint-disable @typescript-eslint/camelcase */
/* eslint-disable camelcase */
const ADAPTER_NAME = 'myAdapter'

describe('ducktype_type_elements', () => {
Expand Down

0 comments on commit 0b5f25a

Please sign in to comment.