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

2731: Add linting rule for arrays #2970

Merged
merged 6 commits into from
Nov 6, 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
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ module.exports = {
allowNullableString: true,
},
],
'@typescript-eslint/array-type': [
'error',
{
default: 'array',
},
],
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',

Expand Down
4 changes: 2 additions & 2 deletions build-configs/BuildConfigType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export type CommonBuildConfigType = {
// Host name of the web app, used for sharing, deep linking and social media previews.
hostName: string
// Hostnames from which resources are automatically downloaded for offline usage.
allowedHostNames: Array<string>
allowedHostNames: string[]
// Linked hosts that can may look similar https://chromium.googlesource.com/chromium/src/+/master/docs/security/lookalikes/lookalike-domains.md#automated-warning-removal
allowedLookalikes: Array<string>
allowedLookalikes: string[]
// Regex defining which urls to intercept as they are internal ones.
supportedIframeSources: string[]
internalLinksHijackPattern: string
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/native/test/helpers/Selector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class Selector {
private queries: Array<string> = new Array<string>()
private queries: string[] = new Array<string>()

public ByText(text: string): Selector {
if (driver.isAndroid) {
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/web/wdio.conf.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { browsers, ciCapabilities } from './capabilities.js'
import waitForLocalhost from './waitForLocalhost.js'

const getCapabilities = (): Array<WebdriverIO.Capabilities> => {
const getCapabilities = (): WebdriverIO.Capabilities[] => {
if (process.env.CI) {
return [ciCapabilities]
}
Expand Down
4 changes: 2 additions & 2 deletions native/src/__mocks__/react-native-blob-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const existsMock = (file: string): Promise<boolean> => {
return Promise.resolve(exists || isParentOfExisting)
}

const lsMock = (path: string): Promise<Array<string>> => {
const lsMock = (path: string): Promise<string[]> => {
const filesInPath = Object.keys(mockFiles).filter(filePath => filePath.startsWith(path))
return Promise.resolve(filesInPath)
}
Expand Down Expand Up @@ -58,7 +58,7 @@ export default {
},
},
fs: {
ls: jest.fn<Promise<Array<string>>, [string]>(lsMock),
ls: jest.fn<Promise<string[]>, [string]>(lsMock),
exists: jest.fn<Promise<boolean>, [string]>(existsMock),
isDir: jest.fn<Promise<boolean>, [string]>(async () => true),
writeFile: jest.fn<Promise<void>, [string, string, string]>(writeMockFile),
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/CitySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SearchBar = styled.View`
`

type CitySelectorProps = {
cities: Array<CityModel>
cities: CityModel[]
navigateToDashboard: (city: CityModel) => void
}

Expand Down
4 changes: 2 additions & 2 deletions native/src/components/CustomHeaderButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const onOverflowMenuPress = (cancelButtonLabel: string) => (props: OnOverflowMen

const CustomHeaderButtons = (props: {
cancelLabel: string
items: Array<ReactNode>
overflowItems: Array<ReactNode>
items: ReactNode[]
overflowItems: ReactNode[]
}): ReactElement => {
const { cancelLabel, items, overflowItems } = props
const { t } = useTranslation('common')
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const NoItemsMessage = styled.Text`
`

type ListProps<T> = {
items: Array<T>
items: T[]
noItemsMessage?: ReactElement | string
renderItem: (props: { item: T; index: number }) => ReactElement
Header?: ReactElement
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/NearbyCities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const StyledIcon = styled(Icon)`
`

type NearbyCitiesProps = {
cities: Array<CityModel>
cities: CityModel[]
navigateToDashboard: (city: CityModel) => void
filterText: string
}
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/News.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const getPageTitle = (
return t('localNews.pageTitle')
}

type NewsModelsType = Array<LocalNewsModel | TunewsModel>
type NewsModelsType = (LocalNewsModel | TunewsModel)[]

type NewsProps = {
news: NewsModelsType
Expand Down
2 changes: 1 addition & 1 deletion native/src/components/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Wrapper = styled.View`
`

type SelectorProps = {
items: Array<SelectorItemModel>
items: SelectorItemModel[]
selectedItemCode: string | null
}

Expand Down
2 changes: 1 addition & 1 deletion native/src/components/__tests__/News.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('News', () => {
localNewsEnabled = true,
}: {
newsId?: number | null
data?: Array<LocalNewsModel | TunewsModel>
data?: (LocalNewsModel | TunewsModel)[]
loadingMore?: boolean
selectedNewsType?: TuNewsType | LocalNewsType
tuNewsEnabled?: boolean
Expand Down
4 changes: 2 additions & 2 deletions native/src/constants/NavigationTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export type RoutesParamsType = {
}
[LICENSES_ROUTE]: undefined
[CHANGE_LANGUAGE_MODAL_ROUTE]: {
languages: Array<LanguageModel>
availableLanguages: Array<string>
languages: LanguageModel[]
availableLanguages: string[]
}
[PDF_VIEW_MODAL_ROUTE]: {
url: string
Expand Down
4 changes: 2 additions & 2 deletions native/src/navigation/navigateToLanguageChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const navigateToLanguageChange = <T extends RoutesType>({
availableLanguages,
}: {
navigation: NavigationProps<T>
languages: Array<LanguageModel>
availableLanguages: Array<string>
languages: LanguageModel[]
availableLanguages: string[]
}): void => {
sendTrackingSignal({
signal: {
Expand Down
2 changes: 1 addition & 1 deletion native/src/routes/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const PageDetailsContainer = styled.View`

export type EventsProps = {
slug?: string
events: Array<EventModel>
events: EventModel[]
cityModel: CityModel
language: string
navigateTo: (routeInformation: RouteInformationType) => void
Expand Down
2 changes: 1 addition & 1 deletion native/src/routes/Intro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const Intro = ({ route, navigation }: IntroProps): ReactElement => {

const renderSlide = ({ item }: { item: SlideContentType }) => <SlideContent item={item} width={width} />

const onViewableItemsChanged = useCallback(({ viewableItems }: { viewableItems: Array<ViewToken> }) => {
const onViewableItemsChanged = useCallback(({ viewableItems }: { viewableItems: ViewToken[] }) => {
const viewableItem = viewableItems[0]
if (viewableItem) {
if (viewableItem.index !== null) {
Expand Down
2 changes: 1 addition & 1 deletion native/src/routes/Pois.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const getBottomSheetSnapPoints = (deviceHeight: number): [number, number, number
]

type PoisProps = {
pois: Array<PoiModel>
pois: PoiModel[]
cityModel: CityModel
language: string
refresh: () => void
Expand Down
2 changes: 1 addition & 1 deletion native/src/routes/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Wrapper = styled.View`
`

export type SearchModalProps = {
allPossibleResults: Array<SearchResult>
allPossibleResults: SearchResult[]
languageCode: string
cityCode: string
closeModal: (query: string) => void
Expand Down
2 changes: 1 addition & 1 deletion native/src/utils/AppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type SettingsType = {
apiUrlOverride: string | null
jpalTrackingEnabled: boolean | null
jpalTrackingCode: string | null
jpalSignals: Array<SignalType>
jpalSignals: SignalType[]
externalSourcePermissions: ExternalSourcePermissions
}
export const defaultSettings: SettingsType = {
Expand Down
16 changes: 8 additions & 8 deletions native/src/utils/DataContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ export type DataContainer = {
* Returns an Array of PoiModels.
* @throws Will throw an error if the array is null.
*/
getPois: (city: string, language: string) => Promise<Array<PoiModel>>
getPois: (city: string, language: string) => Promise<PoiModel[]>

/**
* Sets the pois and persist them ?
*/
setPois: (city: string, language: string, pois: Array<PoiModel>) => Promise<void>
setPois: (city: string, language: string, pois: PoiModel[]) => Promise<void>

/**
* Returns an Array of CityModels.
* @throws Will throw an error if the array is null.
*/
getCities: () => Promise<Array<CityModel>>
getCities: () => Promise<CityModel[]>

/**
* Sets the cities but does not persist them.
* For now switching cities when offline is not possible.
*/
setCities: (cities: Array<CityModel>) => Promise<void>
setCities: (cities: CityModel[]) => Promise<void>

/**
* Returns the CategoriesMapModel.
Expand All @@ -49,23 +49,23 @@ export type DataContainer = {
* Returns an Array of events.
* @throws Will throw an error if the array is null.
*/
getEvents: (city: string, language: string) => Promise<Array<EventModel>>
getEvents: (city: string, language: string) => Promise<EventModel[]>

/**
* Sets the events and persists them.
*/
setEvents: (city: string, language: string, events: Array<EventModel>) => Promise<void>
setEvents: (city: string, language: string, events: EventModel[]) => Promise<void>

/**
* Returns an Array of local news.
* @throws Will throw an error if the array is null.
*/
getLocalNews: (city: string, language: string) => Promise<Array<LocalNewsModel>>
getLocalNews: (city: string, language: string) => Promise<LocalNewsModel[]>

/**
* Sets the local news and persists them.
*/
setLocalNews: (city: string, language: string, events: Array<LocalNewsModel>) => Promise<void>
setLocalNews: (city: string, language: string, events: LocalNewsModel[]) => Promise<void>

/**
* Returns the ResourceCache.
Expand Down
18 changes: 9 additions & 9 deletions native/src/utils/DatabaseConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ContentCategoryJsonType = {
thumbnail: string | null
available_languages: Record<string, string>
parent_path: string
children: Array<string>
children: string[]
order: number
organization: {
name: string
Expand Down Expand Up @@ -279,7 +279,7 @@ class DatabaseConnector {
this._storeMetaCities(metaData)
}

async _deleteMetaOfCities(cities: Array<string>): Promise<void> {
async _deleteMetaOfCities(cities: string[]): Promise<void> {
const metaCities = await this._loadMetaCities()
cities.forEach(city => delete metaCities[city])
await this._storeMetaCities(metaCities)
Expand Down Expand Up @@ -342,7 +342,7 @@ class DatabaseConnector {
await this.writeFile(path, JSON.stringify(citiesMetaJson))
}

async loadLastUsages(): Promise<Array<CityLastUsageType>> {
async loadLastUsages(): Promise<CityLastUsageType[]> {
const metaData = await this._loadMetaCities()
return map<MetaCitiesType, CityLastUsageType>(metaData, (value, key) => ({
city: key,
Expand Down Expand Up @@ -437,7 +437,7 @@ class DatabaseConnector {
return this.readFile(path, mapCategoriesJson)
}

async storePois(pois: Array<PoiModel>, context: DatabaseContext): Promise<void> {
async storePois(pois: PoiModel[], context: DatabaseContext): Promise<void> {
const jsonModels = pois.map(
(poi: PoiModel): ContentPoiJsonType => ({
path: poi.path,
Expand Down Expand Up @@ -484,7 +484,7 @@ class DatabaseConnector {
await this.writeFile(this.getContentPath('pois', context), JSON.stringify(jsonModels))
}

async loadPois(context: DatabaseContext): Promise<Array<PoiModel>> {
async loadPois(context: DatabaseContext): Promise<PoiModel[]> {
const path = this.getContentPath('pois', context)
const mapPoisJson = (json: ContentPoiJsonType[]) =>
json.map(jsonObject => {
Expand Down Expand Up @@ -569,7 +569,7 @@ class DatabaseConnector {
return this.readFile(path, mapLocalNewsJson)
}

async storeCities(cities: Array<CityModel>): Promise<void> {
async storeCities(cities: CityModel[]): Promise<void> {
const jsonModels = cities.map(
(city: CityModel): ContentCityJsonType => ({
name: city.name,
Expand All @@ -592,7 +592,7 @@ class DatabaseConnector {
await this.writeFile(this.getCitiesPath(), JSON.stringify(jsonModels))
}

async loadCities(): Promise<Array<CityModel>> {
async loadCities(): Promise<CityModel[]> {
const path = this.getCitiesPath()
const mapCityJson = (json: ContentCityJsonType[]) =>
json.map(
Expand All @@ -619,7 +619,7 @@ class DatabaseConnector {
return this.readFile(path, mapCityJson)
}

async storeEvents(events: Array<EventModel>, context: DatabaseContext): Promise<void> {
async storeEvents(events: EventModel[], context: DatabaseContext): Promise<void> {
const jsonModels = events.map(
(event: EventModel): ContentEventJsonType => ({
path: event.path,
Expand Down Expand Up @@ -663,7 +663,7 @@ class DatabaseConnector {
await this.writeFile(this.getContentPath('events', context), JSON.stringify(jsonModels))
}

async loadEvents(context: DatabaseContext): Promise<Array<EventModel>> {
async loadEvents(context: DatabaseContext): Promise<EventModel[]> {
const path = this.getContentPath('events', context)
const mapEventsJson = (json: ContentEventJsonType[]) =>
json.map(jsonObject => {
Expand Down
Loading
Loading