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

chore(common): upgrade eslint #405

Merged
merged 7 commits into from
Sep 25, 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: 0 additions & 6 deletions .eslintignore

This file was deleted.

132 changes: 0 additions & 132 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Lint
run: |
yarn eslint packages/field-plugin
yarn workspaces foreach --include "helper-*" run lint
yarn eslint packages/manifest-helper
- name: Test
run: |
yarn workspace @storyblok/field-plugin test
Expand Down
63 changes: 63 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import globals from 'globals'
import eslintJs from '@eslint/js'
import tsEslint from 'typescript-eslint'
import prettier from 'eslint-config-prettier'
import react from 'eslint-plugin-react'
import vue from 'eslint-plugin-vue'
import vueParser from 'vue-eslint-parser'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'

export default [
// Base configuration
{
ignores: ['**/node_modules/', '**/dist/'],
},
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ languageOptions: { globals: { ...globals.browser, ...globals.node } } },
prettier,
eslintJs.configs.recommended,
...tsEslint.configs.recommended,

// Vue.js configuration
...vue.configs['flat/recommended'],
{
files: ['**/*.vue'],
languageOptions: {
parser: vueParser,
parserOptions: {
parser: tsEslint.parser,
},
},
},

// React configuration
react.configs.flat.recommended,
react.configs.flat['jsx-runtime'],
{
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
},

// Custom rules
{
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
'react/prop-types': 'off',
'vue/multi-word-component-names': 'off',
},
},
]
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@
"bump-version": "./scripts/bump-version.ts"
},
"devDependencies": {
"@eslint/js": "9.11.0",
"@storyblok/mui": "0.2.0",
"@types/node": "18.19.17",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "8.56.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-functional": "^4.2.2",
"eslint-plugin-prettier": "^5.1.3",
"eslint": "9.11.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-react": "7.36.1",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-react-refresh": "0.4.12",
"eslint-plugin-vue": "9.28.0",
"globals": "15.9.0",
"kleur": "4.1.5",
"prettier": "^3.2.5",
"prompts": "2.4.2",
"semver": "7.6.0",
"tsx": "3.14.0",
"typescript": "^5.3.3",
"typescript-eslint": "8.6.0",
"vite": "5.1.3",
"vite-plugin-dts": "1.7.3",
"vue-eslint-parser": "9.4.3",
"zx": "7.2.3"
}
}
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
"@types/fs-extra": "11.0.4",
"@types/prompts": "2.4.9",
"temp-dir": "3.0.0",
"vitest": "1.3.0"
"vitest": "2.1.1"
}
}
4 changes: 0 additions & 4 deletions packages/cli/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ describe('utils', () => {
describe('dotEnvPath is given', () => {
it('returns error if env file does not have token', async () => {
vi.mocked(existsSync).mockImplementation(() => true)
// eslint-disable-next-line functional/immutable-data
delete process.env.STORYBLOK_PERSONAL_ACCESS_TOKEN
const result = await getPersonalAccessToken({
token: undefined,
Expand All @@ -74,7 +73,6 @@ describe('utils', () => {

it('returns token if env file has token', async () => {
vi.mocked(existsSync).mockImplementation(() => true)
// eslint-disable-next-line functional/immutable-data
process.env.STORYBLOK_PERSONAL_ACCESS_TOKEN = 'my-token'
const result = await getPersonalAccessToken({
token: undefined,
Expand All @@ -90,7 +88,6 @@ describe('utils', () => {
describe('dotEnvPath is not given', () => {
it('returns error if env files do not have token', async () => {
vi.mocked(existsSync).mockImplementation(() => true)
// eslint-disable-next-line functional/immutable-data
delete process.env.STORYBLOK_PERSONAL_ACCESS_TOKEN
const result = await getPersonalAccessToken({
token: undefined,
Expand All @@ -108,7 +105,6 @@ describe('utils', () => {

it('returns token if env files have token', async () => {
vi.mocked(existsSync).mockImplementation(() => true)
// eslint-disable-next-line functional/immutable-data
process.env.STORYBLOK_PERSONAL_ACCESS_TOKEN = 'my-token'
const result = await getPersonalAccessToken({
token: undefined,
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/commands/__tests__/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import { randomString } from '../../utils'
import { vi } from 'vitest'

vi.mock('../../utils', async () => {
const actualUtils = await vi.importActual<typeof import('../../utils')>(
'../../utils',
)
const actualUtils =
await vi.importActual<typeof import('../../utils')>('../../utils')

return {
...actualUtils,
Expand Down Expand Up @@ -39,11 +38,11 @@ describe('add', () => {
expect(files).toMatchInlineSnapshot(`
[
".env.local.example",
".eslintrc.cjs",
".gitignore",
".nvmrc",
".prettierrc",
"README.md",
"eslint.config.js",
"field-plugin.config.json",
"index.html",
"package.json",
Expand Down Expand Up @@ -78,11 +77,11 @@ describe('add', () => {
)
expect(files).toMatchInlineSnapshot(`
[
".eslintrc.cjs",
".gitignore",
".nvmrc",
".prettierrc",
"README.md",
"eslint.config.js",
"field-plugin.config.json",
"index.html",
"package.json",
Expand Down
13 changes: 6 additions & 7 deletions packages/cli/src/commands/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ vi.mock('fs')

describe('deploy', () => {
const exit = vi.fn(() => {
// eslint-disable-next-line functional/no-throw-statement
throw new Error('Exiting Process Error')
})

Expand Down Expand Up @@ -128,32 +127,32 @@ const defaultDeployArgs: DeployArgs = {
}

const mockPersonalAccessTokenSuccess = () =>
vi.mocked(getPersonalAccessToken).mockImplementation((params) => {
vi.mocked(getPersonalAccessToken).mockImplementation(() => {
return Promise.resolve({ error: false, token: 'token' })
})
const mockPersonalAccessTokenError = () =>
vi.mocked(getPersonalAccessToken).mockImplementation((params) => {
vi.mocked(getPersonalAccessToken).mockImplementation(() => {
return Promise.resolve({
error: true,
message: 'getPersonalAccessToken Error',
})
})

const mockPackageJsonNameError = () =>
vi.mocked(getPackageName).mockImplementation((name) => {
vi.mocked(getPackageName).mockImplementation(() => {
return Promise.resolve({ error: true })
})
const mockPackageJsonNameSuccess = () =>
vi.mocked(getPackageName).mockImplementation((name) => {
vi.mocked(getPackageName).mockImplementation(() => {
return Promise.resolve({ error: false, name: 'test name' })
})
const mockPackageJsonNameSuccessEmpty = () =>
vi.mocked(upsertFieldPlugin).mockImplementation((name) => {
vi.mocked(upsertFieldPlugin).mockImplementation(() => {
return Promise.resolve({ id: 1 })
})

const mockUpsertFieldPluginSuccess = () =>
vi.mocked(upsertFieldPlugin).mockImplementation((name) => {
vi.mocked(upsertFieldPlugin).mockImplementation(() => {
return Promise.resolve({ id: 1 })
})

Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ export const add: AddFunc = async (args) => {
readFileSync(file).toString(),
) as PackageJson

// eslint-disable-next-line functional/immutable-data
packageJson['name'] = packageName

if (args.structure === 'monorepo') {
// eslint-disable-next-line functional/immutable-data, @typescript-eslint/no-unsafe-member-access
packageJson['scripts']['deploy'] += " --dotEnvPath '../../.env'"
}

Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/create/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ vi.mock('../monorepo')
vi.mock('../standalone')

describe('create', () => {
// eslint-disable-next-line functional/no-let
let utils: typeof import('../../../utils')

beforeAll(async () => {
Expand Down
Loading
Loading