Skip to content

Commit

Permalink
improve developer QoL and modernize 🧹 (#2386)
Browse files Browse the repository at this point in the history
* build: upgrade to eslint v9

* style: apply new eslint rules and improve consistency with public cma codebase

* chore: remove browser bundle file from repo

* test: ensure headless browser is installed before running tests

* test: ensure prettier ignores our bundle in the test folder

* build: update to latest puppeteer

* feat: use lint-staged to only check files actually added to the commit
  • Loading branch information
axe312ger authored Feb 3, 2025
1 parent 0203e54 commit 9991a64
Show file tree
Hide file tree
Showing 45 changed files with 1,622 additions and 2,690 deletions.
32 changes: 0 additions & 32 deletions .eslintrc.cjs

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
dist
gh-pages
test/output-integration/browser/public/contentful*.js

# Esdoc dirs
out
Expand Down
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
npm run lint
npm run prettier:check
lint-staged
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/output-integration/browser/public/contentful.browser.min.js
43 changes: 43 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// @ts-check

import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{
ignores: ['test/output-integration/*'],
},
eslint.configs.recommended,
tseslint.configs.recommended,
// Library
{
files: ['lib/**/*'],
rules: {
// Things we probably should fix at some point
'@typescript-eslint/ban-ts-comment': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-unsafe-function-type': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-namespace': 'warn',
// Things we won't allow
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-this-alias': [
'error',
{
allowDestructuring: true, // Allow `const { props, state } = this`; false by default
allowedNames: ['self'], // Allow `const self = this`; `[]` by default
},
],
},
},
// Tests
{
files: ['test/**/*'],
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/ban-ts-comment': 'warn',
},
},
)
9 changes: 5 additions & 4 deletions lib/create-contentful-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
*/

import { encodeCPAResponse } from '@contentful/content-source-maps'
import { AxiosInstance, createRequestConfig, errorHandler } from 'contentful-sdk-core'
import { CreateClientParams } from './contentful.js'
import { GetGlobalOptions } from './create-global-options.js'
import type { AxiosInstance } from 'contentful-sdk-core'
import { createRequestConfig, errorHandler } from 'contentful-sdk-core'
import type { CreateClientParams } from './contentful.js'
import type { GetGlobalOptions } from './create-global-options.js'
import pagedSync from './paged-sync.js'
import type {
Asset,
Expand Down Expand Up @@ -34,7 +35,7 @@ import normalizeSelect from './utils/normalize-select.js'
import resolveCircular from './utils/resolve-circular.js'
import getQuerySelectionSet from './utils/query-selection-set.js'
import validateTimestamp from './utils/validate-timestamp.js'
import { ChainOptions, ModifiersFromOptions } from './utils/client-helpers.js'
import type { ChainOptions, ModifiersFromOptions } from './utils/client-helpers.js'
import {
checkIncludeContentSourceMapsParamIsAllowed,
validateLocaleParam,
Expand Down
1 change: 0 additions & 1 deletion lib/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// eslint-disable-next-line no-unused-vars
declare const __VERSION__: string
5 changes: 3 additions & 2 deletions lib/make-client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import createContentfulApi, { CreateContentfulApiParams } from './create-contentful-api.js'
import {
import type { CreateContentfulApiParams } from './create-contentful-api.js'
import createContentfulApi from './create-contentful-api.js'
import type {
ChainOptions,
DefaultChainOption,
ChainOption,
Expand Down
5 changes: 3 additions & 2 deletions lib/paged-sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import resolveResponse from 'contentful-resolve-response'
import { AxiosInstance, createRequestConfig, freezeSys, toPlainObject } from 'contentful-sdk-core'
import type { AxiosInstance } from 'contentful-sdk-core'
import { createRequestConfig, freezeSys, toPlainObject } from 'contentful-sdk-core'
import mixinStringifySafe from './mixins/stringify-safe.js'
import type {
SyncPageQuery,
Expand All @@ -12,7 +13,7 @@ import type {
LocaleCode,
EntrySkeletonType,
} from './types/index.js'
import { ChainOptions, ModifiersFromOptions } from './utils/client-helpers.js'
import type { ChainOptions, ModifiersFromOptions } from './utils/client-helpers.js'

/**
* Retrieves all the available pages for a sync operation
Expand Down
10 changes: 5 additions & 5 deletions lib/types/asset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ContentfulCollection } from './collection.js'
import { LocaleCode } from './locale.js'
import { Metadata } from './metadata.js'
import { EntitySys } from './sys.js'
import { ChainModifiers } from './client.js'
import type { ContentfulCollection } from './collection.js'
import type { LocaleCode } from './locale.js'
import type { Metadata } from './metadata.js'
import type { EntitySys } from './sys.js'
import type { ChainModifiers } from './client.js'

/**
* @category Asset
Expand Down
22 changes: 11 additions & 11 deletions lib/types/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContentType, ContentTypeCollection } from './content-type.js'
import { Space } from './space.js'
import { LocaleCode, LocaleCollection } from './locale.js'
import {
import type { ContentType, ContentTypeCollection } from './content-type.js'
import type { Space } from './space.js'
import type { LocaleCode, LocaleCollection } from './locale.js'
import type {
AssetQueries,
AssetsQueries,
ConceptSchemesQueries,
Expand All @@ -11,13 +11,13 @@ import {
EntrySkeletonType,
TagQueries,
} from './query/index.js'
import { SyncCollection, SyncOptions, SyncQuery } from './sync.js'
import { Tag, TagCollection } from './tag.js'
import { AssetKey } from './asset-key.js'
import { Entry, EntryCollection } from './entry.js'
import { Asset, AssetCollection, AssetFields } from './asset.js'
import { Concept, ConceptCollection } from './concept.js'
import { ConceptScheme, ConceptSchemeCollection } from './concept-scheme.js'
import type { SyncCollection, SyncOptions, SyncQuery } from './sync.js'
import type { Tag, TagCollection } from './tag.js'
import type { AssetKey } from './asset-key.js'
import type { Entry, EntryCollection } from './entry.js'
import type { Asset, AssetCollection, AssetFields } from './asset.js'
import type { Concept, ConceptCollection } from './concept.js'
import type { ConceptScheme, ConceptSchemeCollection } from './concept-scheme.js'

/**
* Client chain modifiers used in all types that depend on the client configuration.
Expand Down
4 changes: 2 additions & 2 deletions lib/types/collection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetSys } from './asset.js'
import { EntrySys } from './entry.js'
import type { AssetSys } from './asset.js'
import type { EntrySys } from './entry.js'

/**
* A wrapper object containing additional information for
Expand Down
4 changes: 2 additions & 2 deletions lib/types/concept-scheme.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnresolvedLink } from './link'
import { LocaleCode } from './locale'
import type { UnresolvedLink } from './link'
import type { LocaleCode } from './locale'

type ISODateString = string

Expand Down
4 changes: 2 additions & 2 deletions lib/types/concept.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnresolvedLink } from './link'
import { LocaleCode } from './locale'
import type { UnresolvedLink } from './link'
import type { LocaleCode } from './locale'

type ISODateString = string

Expand Down
8 changes: 4 additions & 4 deletions lib/types/content-type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ContentfulCollection } from './collection.js'
import { EntryFields } from './entry.js'
import { SpaceLink, EnvironmentLink } from './link.js'
import { BaseSys } from './sys.js'
import type { ContentfulCollection } from './collection.js'
import type { EntryFields } from './entry.js'
import type { SpaceLink, EnvironmentLink } from './link.js'
import type { BaseSys } from './sys.js'
import type { BLOCKS, INLINES } from '@contentful/rich-text-types'

/**
Expand Down
22 changes: 11 additions & 11 deletions lib/types/entry.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Document as RichTextDocument } from '@contentful/rich-text-types'
import { Asset } from './asset.js'
import { ContentfulCollection } from './collection.js'
import { ContentTypeLink, UnresolvedLink } from './link.js'
import { LocaleCode } from './locale.js'
import { Metadata } from './metadata.js'
import { EntrySkeletonType } from './query/index.js'
import { EntitySys } from './sys.js'
import { JsonArray, JsonObject } from 'type-fest'
import { ResourceLink } from './resource-link.js'
import { ChainModifiers } from './client.js'
import type { Document as RichTextDocument } from '@contentful/rich-text-types'
import type { Asset } from './asset.js'
import type { ContentfulCollection } from './collection.js'
import type { ContentTypeLink, UnresolvedLink } from './link.js'
import type { LocaleCode } from './locale.js'
import type { Metadata } from './metadata.js'
import type { EntrySkeletonType } from './query/index.js'
import type { EntitySys } from './sys.js'
import type { JsonArray, JsonObject } from 'type-fest'
import type { ResourceLink } from './resource-link.js'
import type { ChainModifiers } from './client.js'

/**
* System managed metadata for entries
Expand Down
2 changes: 1 addition & 1 deletion lib/types/link.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ResourceLink } from './resource-link.js'
import type { ResourceLink } from './resource-link.js'

/**
* @category Link
Expand Down
4 changes: 2 additions & 2 deletions lib/types/locale.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContentfulCollection } from './collection.js'
import { BaseSys } from './sys.js'
import type { ContentfulCollection } from './collection.js'
import type { BaseSys } from './sys.js'

/**
* @category Entity
Expand Down
2 changes: 1 addition & 1 deletion lib/types/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TagLink, TaxonomyConceptLink } from './link.js'
import type { TagLink, TaxonomyConceptLink } from './link.js'

/**
* User-controlled metadata
Expand Down
8 changes: 6 additions & 2 deletions lib/types/query/equality.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { EntryFields, EntryFieldType, EntryFieldTypes } from '../entry.js'
import { ConditionalQueries, EntryFieldsConditionalQueries, EntrySkeletonType } from './util.js'
import type { EntryFields, EntryFieldType, EntryFieldTypes } from '../entry.js'
import type {
ConditionalQueries,
EntryFieldsConditionalQueries,
EntrySkeletonType,
} from './util.js'

type SupportedTypes =
| EntryFields.Symbol
Expand Down
6 changes: 3 additions & 3 deletions lib/types/query/existence.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EntryField, EntryFieldType } from '../entry.js'
import { ConditionalFixedQueries, FieldsType, EntrySkeletonType } from './util.js'
import { AssetDetails, AssetFile } from '../asset.js'
import type { EntryField, EntryFieldType } from '../entry.js'
import type { ConditionalFixedQueries, FieldsType, EntrySkeletonType } from './util.js'
import type { AssetDetails, AssetFile } from '../asset.js'

/**
* Check for existence of provided fields
Expand Down
4 changes: 2 additions & 2 deletions lib/types/query/location.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConditionalPick } from 'type-fest'
import { EntryFieldTypes } from '../entry.js'
import type { ConditionalPick } from 'type-fest'
import type { EntryFieldTypes } from '../entry.js'

type Types = EntryFieldTypes.Location | undefined

Expand Down
10 changes: 5 additions & 5 deletions lib/types/query/order.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EntrySkeletonType, FieldsType } from './util.js'
import { EntryFields, EntryFieldType, EntryFieldTypes, EntrySys } from '../entry.js'
import { AssetSys } from '../asset.js'
import { ConditionalPick } from 'type-fest'
import { TagSys } from '../tag.js'
import type { EntrySkeletonType, FieldsType } from './util.js'
import type { EntryFields, EntryFieldType, EntryFieldTypes, EntrySys } from '../entry.js'
import type { AssetSys } from '../asset.js'
import type { ConditionalPick } from 'type-fest'
import type { TagSys } from '../tag.js'

export type SupportedTypes =
| EntryFields.Symbol
Expand Down
39 changes: 18 additions & 21 deletions lib/types/query/query.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { AssetDetails, AssetFile, AssetMimeType, AssetSys } from '../asset.js'
import { ChainModifiers } from '../client.js'
import { EntrySys } from '../entry.js'
import { TagLink, TaxonomyConceptLink } from '../link.js'
import { Metadata } from '../metadata.js'
import { TagSys } from '../tag.js'
import {
import type { AssetDetails, AssetFile, AssetMimeType, AssetSys } from '../asset.js'
import type { ChainModifiers } from '../client.js'
import type { EntrySys } from '../entry.js'
import type { TagLink, TaxonomyConceptLink } from '../link.js'
import type { Metadata } from '../metadata.js'
import type { TagSys } from '../tag.js'
import type {
EntryFieldsEqualityFilter,
EntryFieldsInequalityFilter,
EqualityFilter,
InequalityFilter,
} from './equality.js'
import { EntryFieldsExistenceFilter, ExistenceFilter } from './existence.js'
import { LocationSearchFilters } from './location.js'
import {
import type { EntryFieldsExistenceFilter, ExistenceFilter } from './existence.js'
import type { LocationSearchFilters } from './location.js'
import type {
AssetOrderFilter,
TaxonomyOrderFilter,
EntryOrderFilter,
EntryOrderFilterWithFields,
TagOrderFilter,
} from './order.js'
import { EntryFieldsRangeFilters, RangeFilters } from './range.js'
import { ReferenceSearchFilters } from './reference.js'
import { EntryFieldsFullTextSearchFilters, FullTextSearchFilters } from './search.js'
import { AssetSelectFilter, EntrySelectFilter, EntrySelectFilterWithFields } from './select.js'
import { EntryFieldsSetFilter } from './set.js'
import { EntryFieldsSubsetFilters, SubsetFilters } from './subset.js'
import {
import type { EntryFieldsRangeFilters, RangeFilters } from './range.js'
import type { ReferenceSearchFilters } from './reference.js'
import type { EntryFieldsFullTextSearchFilters, FullTextSearchFilters } from './search.js'
import type { AssetSelectFilter, EntrySelectFilter, EntrySelectFilterWithFields } from './select.js'
import type { EntryFieldsSetFilter } from './set.js'
import type { EntryFieldsSubsetFilters, SubsetFilters } from './subset.js'
import type {
ConditionalFixedQueries,
ConditionalListQueries,
EntrySkeletonType,
Expand Down Expand Up @@ -120,7 +120,6 @@ export type EntriesQueries<
FixedQueryOptions &
FixedPagedOptions &
FixedLinkOptions) &
// eslint-disable-next-line @typescript-eslint/ban-types
('WITH_ALL_LOCALES' extends Modifiers ? {} : LocaleOption))

/**
Expand All @@ -129,7 +128,6 @@ export type EntriesQueries<
* @category Query
*/
export type EntryQueries<Modifiers extends ChainModifiers> = Omit<FixedQueryOptions, 'query'> &
// eslint-disable-next-line @typescript-eslint/ban-types
('WITH_ALL_LOCALES' extends Modifiers ? {} : LocaleOption)

/**
Expand Down Expand Up @@ -189,8 +187,7 @@ export type AssetsQueries<
MetadataTagsQueries &
FixedQueryOptions &
FixedPagedOptions & { mimetype_group?: AssetMimeType } & ('WITH_ALL_LOCALES' extends Modifiers
? // eslint-disable-next-line @typescript-eslint/ban-types
{}
? {}
: LocaleOption)

/**
Expand Down
Loading

0 comments on commit 9991a64

Please sign in to comment.