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

updated typescript eslint package #2056

Merged
merged 3 commits into from
May 10, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions eslintrc.js
Original file line number Diff line number Diff line change
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'],
alonstern marked this conversation as resolved.
Show resolved Hide resolved
'jest/valid-describe': ['off'],
'import/extensions': [ 'error', 'never', {
'json': 'always',
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-api/package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 @@ -71,27 +78,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 @@ -105,8 +111,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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",
"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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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