Skip to content

Commit

Permalink
fix(security): disable eslint security output temporarily (#1238)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Apr 2, 2024
1 parent f9b685b commit 476bfba
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion components/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function CopyButton({ code, className }: Props): JSX.Element {
className,
'outline-focus-visible absolute right-5 top-1.5 md:top-1',
)}
// eslint-disable-next-line ts/no-misused-promises
// eslint-disable-next-line ts/no-misused-promises -- no need to handle promise.
onClick={copy}
>
<Toggle
Expand Down
1 change: 1 addition & 0 deletions components/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function Editor({ template = 'react-ts', children }: Props): JSX.Element {
const filePath = normalizeFilepath(filename, language)
const code = codeElement.props.children

// eslint-disable-next-line security/detect-object-injection -- `result` is not to execute.
result[filePath] = {
code,
}
Expand Down
2 changes: 1 addition & 1 deletion components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ErrorBoundary extends Component<Props, State> {
public render() {
const { hasError, error } = this.state
const { children } = this.props
// eslint-disable-next-line node/prefer-global/process
// eslint-disable-next-line node/prefer-global/process -- SWC/Webpack supports process.env.NODE_ENV.
const isDevelopment = process.env.NODE_ENV === 'development'

if (hasError && isDevelopment) {
Expand Down
2 changes: 1 addition & 1 deletion components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Header', () => {
it('should render correctly (snapshot)', async () => {
const { container } = render(<Header posts={mockPosts} />)

// eslint-disable-next-line testing-library/no-wait-for-snapshot
// eslint-disable-next-line testing-library/no-wait-for-snapshot -- Wait for the snapshot to be taken.
await waitFor(() => expect(container).toMatchSnapshot())
})
})
4 changes: 2 additions & 2 deletions components/MDX/MDX.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Divider from './MDXDivider'
import Input from './MDXInput'
import Pre from './MDXPre'

// eslint-disable-next-line ts/no-unsafe-assignment
// eslint-disable-next-line ts/no-unsafe-assignment -- dynamic import.
const Editor = dynamic(() => import('@components/Editor')) as any

const Headings = {
Expand Down Expand Up @@ -46,7 +46,7 @@ const CodeBlocks = {

const customComponents = {
Button,
// eslint-disable-next-line ts/no-unsafe-assignment
// eslint-disable-next-line ts/no-unsafe-assignment -- dynamic import.
Editor,
}

Expand Down
2 changes: 2 additions & 0 deletions components/TagsCloud/TagsCloud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Props {

function TagsCloud({ tags, activeTag }: Props): JSX.Element {
let tagsList = Object.keys(tags).sort((a, b) => {
// eslint-disable-next-line security/detect-object-injection -- key is safe.
return tags[b] - tags[a]
})

Expand All @@ -25,6 +26,7 @@ function TagsCloud({ tags, activeTag }: Props): JSX.Element {
{tagsList.map(tag => (
<LinkTag
key={tag}
// eslint-disable-next-line security/detect-object-injection -- key is safe.
tag={`${tag} ${tags[tag]}`}
href={`/tag/${tag}`}
color={activeTag ? colors.gray : getColorByName(tag)}
Expand Down
2 changes: 2 additions & 0 deletions config/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ function hashString(name: string) {
function getColorByName(name: string): string {
const palette = Object.keys(colorPalette)
const colorIdx = hashString(name) % palette.length
// eslint-disable-next-line security/detect-object-injection -- colorIdx is safe.
const paletteColor = palette[colorIdx] as PaletteColor
// eslint-disable-next-line security/detect-object-injection -- paletteColor is safe.
return colorPalette[paletteColor]
}

Expand Down
4 changes: 2 additions & 2 deletions hooks/useVisibility.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe('useVisibility', () => {

fireEvent.scroll(window, { target: { scrollY: 100 } })

// eslint-disable-next-line testing-library/await-async-utils
// eslint-disable-next-line testing-library/await-async-utils -- no need to await.
void waitFor(() => expect(onBottomPassed).toHaveBeenCalled())
// eslint-disable-next-line testing-library/await-async-utils
// eslint-disable-next-line testing-library/await-async-utils -- no need to await.
void waitFor(() => expect(onBottomPassedReverse).toHaveBeenCalled())
})
})
2 changes: 1 addition & 1 deletion layouts/Layout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Layout', () => {
</Layout>,
)

// eslint-disable-next-line testing-library/no-wait-for-snapshot
// eslint-disable-next-line testing-library/no-wait-for-snapshot -- Wait for the snapshot to be taken.
await waitFor(() => expect(container).toMatchSnapshot())
})
})
2 changes: 1 addition & 1 deletion layouts/PostLayout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('PostLayout', () => {
</PostLayout>,
)

// eslint-disable-next-line testing-library/no-wait-for-snapshot
// eslint-disable-next-line testing-library/no-wait-for-snapshot -- Wait for the snapshot to be taken.
await waitFor(() => expect(container).toMatchSnapshot())
})
})
2 changes: 1 addition & 1 deletion lib/getGitHubData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default async function getGitHubData(): Promise<GitHub> {
}
}
} else {
// eslint-disable-next-line no-console
// eslint-disable-next-line no-console -- need for CLI output.
console.info('Not for Vercel build, fallback to local GitHub data.')
}

Expand Down
8 changes: 7 additions & 1 deletion lib/getPostsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function getReadingTime(content: string): number {
}

async function generatePostData(filePath: string): Promise<PostType> {
// eslint-disable-next-line security/detect-non-literal-fs-filename -- filePath is safe.
const fileContent = await fs.readFile(filePath, 'utf8')
const slug = path.basename(filePath, path.extname(filePath))

Expand Down Expand Up @@ -149,8 +150,13 @@ async function getTagsData(): Promise<TagsType> {
.map(post => post.tags || [])
.flat()
.reduce((tags: TagsType, tag: Tag) => {
if (!tags[tag])
// eslint-disable-next-line security/detect-object-injection -- key is safe.
if (!tags[tag]) {
// eslint-disable-next-line security/detect-object-injection -- key is safe.
tags[tag] = 0
}

// eslint-disable-next-line security/detect-object-injection -- key is safe.
tags[tag] += 1
return tags
}, {})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@dg-scripts/eslint-config": "^5.19.0",
"@dg-scripts/stylelint-config": "^5.19.0",
"@dg-scripts/eslint-config": "^5.20.1",
"@dg-scripts/stylelint-config": "^5.20.1",
"@octokit/types": "^12.6.0",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.2",
Expand Down
45 changes: 34 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 476bfba

Please sign in to comment.