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

Integrate Knip #7847

Merged
merged 27 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
00d2c67
chore: set up knip
jamil314 Oct 25, 2024
89acd2b
chore: remove unused exports from client
jamil314 Oct 25, 2024
8a9f6aa
chore: add lint-knip in CI
jamil314 Oct 25, 2024
2517b4e
feat: CI: compare knip issue count of base branch and pr branch
jamil314 Oct 28, 2024
7089a69
fix: use base_ref directly, write output to GITHUB_OUTPUT
jamil314 Oct 28, 2024
9cfdba5
fix: remove knip script from package.json
jamil314 Oct 28, 2024
6865b73
refactor: remove unused codes from client
jamil314 Oct 29, 2024
3a20d1b
refactor: remove unused codes from commons
jamil314 Oct 29, 2024
d9d8893
fix: remove knip.ts
jamil314 Oct 29, 2024
4817d5f
fix: create knip reporter in pipeline
jamil314 Oct 29, 2024
bcd5c71
chore: merge develop
jamil314 Oct 29, 2024
847c2a5
refactor: remove unused codes from config
jamil314 Oct 29, 2024
fc557c9
fix: remove unused imports and declarations
jamil314 Oct 30, 2024
ed658a1
fix: run knip externally
jamil314 Oct 30, 2024
98ed974
chore: remove knip-reporter
jamil314 Oct 30, 2024
c3b8348
Merge branch 'develop' into ocrvs-7302
jamil314 Oct 30, 2024
5d9a9c5
chore: remove unused imports from config
jamil314 Oct 30, 2024
db1bc50
chore: remove unused imports from client
jamil314 Oct 30, 2024
d01bcc6
amend: export `QUESTION_KEYS`
jamil314 Oct 30, 2024
af9c9ec
Merge branch 'ocrvs-7302' of https://github.com/opencrvs/opencrvs-cor…
jamil314 Oct 30, 2024
fc10c04
amend: export `PaymentSection`
jamil314 Oct 30, 2024
0af184f
refactor: make `create reporter` more readable
jamil314 Oct 30, 2024
4f079a5
chore: remove security scans
jamil314 Oct 31, 2024
4d0ee8d
chore: remove unused devDependenceis
jamil314 Oct 31, 2024
fa63cfb
refactor: move contents of QueryProvider to index.ts
jamil314 Oct 31, 2024
ea55caf
chore: run gql type generator
jamil314 Oct 31, 2024
12c07d4
Merge branch 'develop' into ocrvs-7302
jamil314 Oct 31, 2024
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
39 changes: 39 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,45 @@ jobs:
if: steps.check-scripts.outputs.skip != 'true' && steps.check-scripts.outputs.skip-test != 'true'
run: cd ${{ matrix.package }} && yarn test

lint-knip:
runs-on: ubuntu-22.04
steps:
- name: Checkout the PR branch
uses: actions/checkout@v2

- name: Get the base branch
id: base_branch
run: echo "::set-output name=branch::$(echo '${{ github.base_ref }}' || echo 'main')"
naftis marked this conversation as resolved.
Show resolved Hide resolved

- name: Checkout base branch
uses: actions/checkout@v2
with:
ref: ${{ steps.base_branch.outputs.branch }}
- uses: actions/setup-node@v4
- name: Install dependencies
run: yarn install --ignore-scripts
- name: Run knip on base branch
id: knip_base
run: |
echo "${{ steps.base_branch.outputs.branch }}"
OUTPUT=$(yarn knip --no-exit-code --reporter=./knip-reporter.ts)
echo "Output: $OUTPUT"
JSON=$(echo "$OUTPUT" | grep -o '{.*}')
total_issues=$(echo "$JSON" | jq '.totalIssues')
echo "Total Issues: $total_issues"
echo "::set-output name=maxIssues::$total_issues"

- name: Checkout the PR branch
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v4
- name: Install dependencies
run: yarn install --ignore-scripts
- name: Run knip on PR branch
run: |
yarn knip --max-issues=${{ steps.knip_base.outputs.maxIssues }} --reporter=./knip-reporter.ts
naftis marked this conversation as resolved.
Show resolved Hide resolved

security-scans:
needs: setup
runs-on: ubuntu-22.04
Expand Down
18 changes: 18 additions & 0 deletions knip-reporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this custom reporter? If yes, maybe we could create the file in the pipeline especially given that it would be added to the root of the repository

* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import type { Reporter } from 'knip'

const reporter: Reporter = function (options) {
const { counters } = options
console.log('Total unused exports found with knip:', counters.total)
}

export default reporter
18 changes: 18 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
import type { KnipConfig } from 'knip'

const config: KnipConfig = {
Copy link
Member

Choose a reason for hiding this comment

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

Can you supply these options for the knip command inline so we wouldn't need to add a new file to the root of the project? I'm trying to avoid that as for newcomers these files can feel a bit daunting

entry: ['src/index.ts'],
project: ['src/**/*.ts']
}

export default config
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@
"seed:prod": "NODE_ENV=production lerna run seed --stream --scope @opencrvs/data-seeder",
"add:license": "license-check-and-add add -f license-config.json",
"build:components": "lerna run build --scope @opencrvs/components",
"debug": "bash debug-service-in-chrome.sh"
"debug": "bash debug-service-in-chrome.sh",
"knip": "knip"
naftis marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@types/dotenv": "^6.1.0",
"@types/node": "^22.7.9",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"@types/node": "^22.7.9",

"concurrently": "^8.0.0",
"husky": "^9.1.6",
"knip": "^5.34.0",
"lerna": "^8.0.0",
"lint-staged": "^15.2.10",
"prettier": "2.8.8"
"prettier": "2.8.8",
"typescript": "^5.6.3"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"typescript": "^5.6.3"

},
"dependencies": {
"@types/react-signature-canvas": "^1.0.2",
Expand Down
3 changes: 1 addition & 2 deletions packages/login/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { PageContainer } from '@login/common/PageContainer'
import { ErrorBoundary } from '@login/ErrorBoundary'
import { IntlContainer } from '@login/i18n/components/I18nContainer'
import * as routes from '@login/navigation/routes'
import { AppStore, createStore } from '@login/store'
import { AppStore } from '@login/store'
import { StepOneContainer } from '@login/views/StepOne/StepOneContainer'
import { getTheme } from '@opencrvs/components/lib/theme'
import * as React from 'react'
Expand All @@ -32,7 +32,6 @@ import { LoginBackgroundWrapper } from '@login/common/LoginBackgroundWrapper'
import { StepTwoContainer } from '@login/views/StepTwo/StepTwoContainer'
import { ReloadModal } from './views/ReloadModal'

export const { store, history } = createStore()
interface IAppProps {
store: AppStore
history: History
Expand Down
2 changes: 1 addition & 1 deletion packages/login/src/common/LoginBackgroundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface IProps {
children: React.ReactNode
}

export function usePersistentCountryBackground() {
function usePersistentCountryBackground() {
const theme = useTheme()
const [countryBackground, setCountryBackground] = React.useState({
backgroundColor: `${(theme as ITheme).colors.backgroundPrimary}`,
Expand Down
4 changes: 2 additions & 2 deletions packages/login/src/i18n/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface ILanguageState {
[key: string]: ILanguage
}

export const initLanguages = () => {
const initLanguages = () => {
const initLanguages: ILanguageState = {}
getAvailableLanguages().forEach((lang) => {
initLanguages[lang] = {
Expand All @@ -50,7 +50,7 @@ export type IntlState = {

const DEFAULT_MESSAGES = { default: 'default' }

export const initialState: IntlState = {
const initialState: IntlState = {
language: getDefaultLanguage(),
messages: DEFAULT_MESSAGES,
languages: initLanguages()
Expand Down
27 changes: 4 additions & 23 deletions packages/login/src/login/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export enum FORGOTTEN_ITEMS {
PASSWORD = 'password'
}

export type ApplicationConfigAction = {
type ApplicationConfigAction = {
type: typeof CONFIG_LOAD
}

Expand Down Expand Up @@ -130,12 +130,12 @@ export type VerifyCodeFailedAction = {
payload: Error
}

export type GoToAppAction = {
type GoToAppAction = {
type: typeof GOTO_APP
payload: string
}

export type StoreReloadModalVisibilityAction = {
type StoreReloadModalVisibilityAction = {
type: typeof RELOAD_MODAL_VISIBILITY
payload: { visibility: boolean }
}
Expand All @@ -160,10 +160,6 @@ export type Action =
| StoreClientRedirectRouteAction
| StoreReloadModalVisibilityAction

export const applicationConfigLoadAction = (): ApplicationConfigAction => ({
type: CONFIG_LOAD
})

export const resetSubmissionError = (): AuthenticationResetAction => {
return {
type: AUTHENTICATE_RESET
Expand Down Expand Up @@ -252,15 +248,6 @@ export const storeClientRedirectRoute = (
}
}

export const storeReloadModalVisibility = (
visibility: boolean
): StoreReloadModalVisibilityAction => {
return {
type: RELOAD_MODAL_VISIBILITY,
payload: { visibility }
}
}

export const verifyCode = (values: IVerifyCodeNumbers): VerifyCodeAction => {
const code = Object.values(values).join('')
return {
Expand All @@ -280,13 +267,7 @@ export const failVerifyCode = (error: AxiosError): VerifyCodeFailedAction => ({
type: VERIFY_CODE_FAILED,
payload: error
})
export function goBack() {
return back()
}
export const gotoApp = (appId: string): GoToAppAction => ({
type: GOTO_APP,
payload: appId
})

export function goToForgottenItemForm() {
return push(FORGOTTEN_ITEM)
}
Expand Down
8 changes: 0 additions & 8 deletions packages/login/src/login/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ export function selectApplicationName(store: IStoreState) {
return getKey(store, 'config').APPLICATION_NAME
}

export function selectImageToObjectFit(store: IStoreState) {
if (getKey(store, 'config').LOGIN_BACKGROUND?.imageFit) {
return getKey(store, 'config').LOGIN_BACKGROUND?.imageFit
} else {
return getKey(store, 'config').LOGIN_BACKGROUND?.imageFit
}
}

export const getStepOneDetails = (
store: IStoreState
): LoginState['authenticationDetails'] => getKey(store, 'authenticationDetails')
2 changes: 0 additions & 2 deletions packages/login/src/navigation/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ export const RECOVERY_CODE_ENTRY = '/recovery-code'
export const SECURITY_QUESTION = '/security-question'
export const UPDATE_PASSWORD = '/reset-password'
export const SUCCESS = '/success'

export const REGISTER_APP = 'register'
4 changes: 2 additions & 2 deletions packages/login/src/utils/authApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'
import * as Sentry from '@sentry/react'

export interface ICodeVerifyData {
interface ICodeVerifyData {
nonce: string
code: string
}
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface IAuthenticateResponse {
email?: string
}

export enum QUESTION_KEYS {
enum QUESTION_KEYS {
BIRTH_TOWN = 'BIRTH_TOWN',
HIGH_SCHOOL = 'HIGH_SCHOOL',
MOTHER_NAME = 'MOTHER_NAME',
Expand Down
5 changes: 1 addition & 4 deletions packages/login/src/utils/authUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
import decode from 'jwt-decode'
import * as Sentry from '@sentry/react'

export const ERROR_CODE_TOO_MANY_ATTEMPTS = 429
export const ERROR_CODE_FIELD_MISSING = 500
export const ERROR_CODE_INVALID_CREDENTIALS = 401
export const ERROR_CODE_FORBIDDEN_CREDENTIALS = 403
export const ERROR_CODE_PHONE_NUMBER_VALIDATE = 503
export interface IURLParams {
[key: string]: string | string[] | undefined
}

export interface ITokenPayload {
subject: string
exp: string
Expand Down
4 changes: 0 additions & 4 deletions packages/login/src/utils/dataCleanse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,3 @@ export const convertToMSISDN = (phone: string, alpha3CountryCode: string) => {
.replace(/[\s-]/g, '')
)
}

export const getMSISDNCountryCode = (countryCode: string) => {
return callingCountries[countryCode.toUpperCase()].countryCallingCodes[0]
}
5 changes: 0 additions & 5 deletions packages/login/src/utils/fieldUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export type Ii18nReduxFormFieldProps = {
focusInput: boolean
}

export type IReduxFormFieldProps = {
placeholder?: MessageDescriptor
label?: MessageDescriptor
} & Omit<Ii18nReduxFormFieldProps, 'placeholder' | 'label'>

export type IFieldGroup = {
[key: string]: Ii18nReduxFormFieldProps
}
2 changes: 1 addition & 1 deletion packages/login/src/utils/referenceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import { IntlMessages } from '@login/i18n/reducer'
import { request } from './authApi'

export interface ILanguage {
interface ILanguage {
lang: string
displayName: string
messages: IntlMessages
Expand Down
4 changes: 2 additions & 2 deletions packages/login/src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { MessageDescriptor } from 'react-intl'
import { PrimitiveType } from 'intl-messageformat'
import { messages } from '@login/i18n/messages/validations'
import { validate as validateEmail } from 'email-validator'
export interface IValidationResult {
interface IValidationResult {
message: MessageDescriptor
props?: { [key: string]: PrimitiveType }
}
Expand All @@ -23,7 +23,7 @@ export const isAValidPhoneNumberFormat = (value: string): boolean => {
const pattern = window.config.PHONE_NUMBER_PATTERN
return new RegExp(pattern).test(value)
}
export const isAValidEmailAddressFormat = (value: string): boolean => {
const isAValidEmailAddressFormat = (value: string): boolean => {
return validateEmail(value)
}

Expand Down
6 changes: 0 additions & 6 deletions packages/login/src/views/Common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export const LogoContainer = styled.div`
}
`

export interface IProps {
formId: string
submissionError: boolean
errorCode?: number
}

export const Container = styled.div`
position: relative;
height: auto;
Expand Down
19 changes: 0 additions & 19 deletions packages/login/src/views/ResetCredentialsForm/Commons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,6 @@
*/
import styled from 'styled-components'

export const Title = styled.div`
${({ theme }) => theme.fonts.h2};
color: ${({ theme }) => theme.colors.copy};
`
export const Page = styled.div`
color: ${({ theme }) => theme.colors.copy};
background: ${({ theme }) => theme.colors.white};
min-height: 100vh;
display: flex;
flex-direction: column;
text-align: center;
`
export const Container = styled.div`
position: relative;
height: auto;
padding: 0px;
margin: 125px auto 0px auto;
max-width: 460px;
`
export const LogoContainer = styled.div`
flex-direction: row;
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Props = { goToHome: typeof goToHome } & RouteComponentProps<
> &
IntlShapeProps & { logo: string | undefined }

export const ResetCredentialsSuccessView = (props: Props) => {
const ResetCredentialsSuccessView = (props: Props) => {
const { logo, goToHome, intl, location } = props
const { forgottenItem } = location.state

Expand Down
Loading
Loading