Skip to content

Commit

Permalink
feat: add eslint-config-cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
benny123tw committed Aug 25, 2023
1 parent 49ab9c6 commit ba52938
Show file tree
Hide file tree
Showing 18 changed files with 481 additions and 340 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- run: pnpm install
- run: pnpm lint
- run: pnpm vitest run
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"version": "0.0.2",
"private": true,
"workspaces": [
"packages/*"
],
"packageManager": "pnpm@8.6.12",
"scripts": {
"lint": "eslint . --config=packages/eslint-config/index.cjs",
"lint": "eslint . --config=packages/eslint-config-ts/index.cjs",
"release": "pnpm test && bumpp -r && pnpm publish -r --no-git-checks",
"test": "pnpm lint && vitest run"
},
"devDependencies": {
"@benny123tw/eslint-config-ts": "workspace:*",
"bumpp": "^9.2.0",
"eslint": "^8.43.0",
"vitest": "^0.32.2",
"eslint": "^8.47.0",
"prettier": "^3.0.2",
"vitest": "^0.34.3",
"vue": "^3.3.4"
},
"packageManager": "pnpm@8.6.2",
"version": "0.0.2"
"eslintConfig": {
"extends": [
"@benny123tw/eslint-config-ts"
]
}
}
29 changes: 29 additions & 0 deletions packages/eslint-config-cypress/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const prettierRules = require('@benny123tw/prettier-config')

/** @type {import('eslint').ESLint.ConfigData} */
const config = {
extends: ['@antfu/eslint-config-ts', 'plugin:prettier/recommended'],
plugins: ['cypress'],
rules: {
'prettier/prettier': [
'error',
{
...prettierRules,
},
],

// See: https://typescript-eslint.io/rules/brace-style/
'brace-style': 'off',
'@typescript-eslint/brace-style': 'error',

// cypress
'cypress/no-assigning-return-values': 'error',
'cypress/no-unnecessary-waiting': 'warn',
'cypress/assertion-before-screenshot': 'warn',
'cypress/no-force': 'off',
'cypress/no-async-tests': 'error',
'cypress/no-pause': 'error',
},
}

module.exports = config
29 changes: 29 additions & 0 deletions packages/eslint-config-cypress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@benny123tw/eslint-config-cypress",
"version": "0.0.2",
"description": "ESLint Cypress config for Benny personal usage",
"author": "Benny Yen <benny123tw@gmail.com>",
"license": "MIT",
"homepage": "https://github.com/benny123tw/eslint-config",
"repository": "https://github.com/benny123tw/eslint-config.git",
"exports": {
".": "./index.cjs"
},
"main": "index.cjs",
"files": [
"index.cjs"
],
"peerDependencies": {
"eslint": ">=8.44.0",
"typescript": ">=3.9"
},
"dependencies": {
"@antfu/eslint-config-ts": "^0.41.0",
"@benny123tw/prettier-config": "workspace:*",
"eslint-plugin-cypress": "^2.14.0"
},
"devDependencies": {
"@types/eslint": "^8.44.2",
"eslint": "^8.47.0"
}
}
20 changes: 20 additions & 0 deletions packages/eslint-config-cypress/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
import { ESLint } from 'eslint'

describe('eslint-config', () => {
it('loads config in eslint to validate all rule syntax is correct', async () => {
const cli = new ESLint({
useEslintrc: false,
overrideConfigFile: fileURLToPath(new URL('../index.cjs', import.meta.url)),
})

const code = "const foo = 1\nconst bar = function () {}\nbar(foo)\nconst dummy = 'test'\n"

const [{ errorCount }] = await cli.lintText(code, { filePath: 'test.ts' })
expect(errorCount).toEqual(0)

const rules = await cli.calculateConfigForFile('test.ts')
expect(rules.plugins).toContain('cypress')
})
})
21 changes: 9 additions & 12 deletions packages/eslint-config-ts/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@ const prettierRules = require('@benny123tw/prettier-config')

/** @type {import('eslint').ESLint.ConfigData} */
const config = {
extends: [
'@antfu/eslint-config-ts',
'plugin:prettier/recommended',
],
extends: ['@antfu/eslint-config-ts', 'plugin:prettier/recommended'],
rules: {
"prettier/prettier": [
"error",
'prettier/prettier': [
'error',
{
...prettierRules
}
...prettierRules,
},
],

// See: https://typescript-eslint.io/rules/brace-style/
"brace-style": "off",
"@typescript-eslint/brace-style": "error"
}
'brace-style': 'off',
'@typescript-eslint/brace-style': 'error',
},
}

module.exports = config;
module.exports = config
18 changes: 9 additions & 9 deletions packages/eslint-config-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
"version": "0.0.2",
"description": "ESLint Typescript config for Benny personal usage",
"author": "Benny Yen <benny123tw@gmail.com>",
"repository": "https://github.com/benny123tw/eslint-config.git",
"homepage": "https://github.com/benny123tw/eslint-config",
"license": "MIT",
"main": "index.cjs",
"homepage": "https://github.com/benny123tw/eslint-config",
"repository": "https://github.com/benny123tw/eslint-config.git",
"exports": {
".": "./index.cjs"
},
"main": "index.cjs",
"files": [
"index.cjs"
],
"peerDependencies": {
"eslint": ">=8.44.0",
"typescript": ">=3.9"
},
"dependencies": {
"@antfu/eslint-config-ts": "^0.41.0",
"@benny123tw/prettier-config": "workspace:*"
},
"devDependencies": {
"@types/eslint": "^8.40.2",
"eslint": "^8.43.0"
},
"peerDependencies": {
"eslint": ">=7.4.0",
"typescript": ">=3.9"
"@types/eslint": "^8.44.2",
"eslint": "^8.47.0"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-config-ts/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'node:url'
import { it, expect, describe } from 'vitest'
import { describe, expect, it } from 'vitest'
import { ESLint } from 'eslint'

describe('eslint-config', () => {
Expand Down
32 changes: 16 additions & 16 deletions packages/eslint-config/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ const config = {
jsx: 'espree',

ts: '@typescript-eslint/parser',
tsx: '@typescript-eslint/parser'
tsx: '@typescript-eslint/parser',
},
extraFileExtensions: ['.vue'],
ecmaFeatures: {
jsx: true
}
jsx: true,
},
},
env: { node: true },
plugins: ['@typescript-eslint'],
Expand All @@ -26,12 +26,12 @@ const config = {
'plugin:prettier/recommended',
],
rules: {
"prettier/prettier": [
"error",
'prettier/prettier': [
'error',
{
...prettierRules
}
]
...prettierRules,
},
],
},
overrides: [
{
Expand All @@ -40,8 +40,8 @@ const config = {
// The core 'no-unused-vars' rules (in the eslint:recommended ruleset)
// does not work with type definitions.
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'warn'
}
'@typescript-eslint/no-unused-vars': 'warn',
},
},
{
// Include typescript eslint rules in *.vue files
Expand Down Expand Up @@ -79,16 +79,16 @@ const config = {
'**/app.{js,ts,jsx,tsx,vue}',
'**/error.{js,ts,jsx,tsx,vue}',
// These files should have multiple words in their names as they are within subdirectories.
'**/components/*/**/*.{js,ts,jsx,tsx,vue}'
'**/components/*/**/*.{js,ts,jsx,tsx,vue}',
],
rules: { 'vue/multi-word-component-names': 'off' }
rules: { 'vue/multi-word-component-names': 'off' },
},
{
// Pages and layouts are required to have a single root element if transitions are enabled.
files: ['**/pages/**/*.{js,ts,jsx,tsx,vue}', '**/layouts/**/*.{js,ts,jsx,tsx,vue}'],
rules: { 'vue/no-multiple-template-root': 'error' }
}
]
rules: { 'vue/no-multiple-template-root': 'error' },
},
],
}

module.exports = config;
module.exports = config
32 changes: 16 additions & 16 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
"version": "0.0.2",
"description": "ESLint config for Benny personal usage",
"author": "Benny Yen <benny123tw@gmail.com>",
"repository": "https://github.com/benny123tw/eslint-config.git",
"homepage": "https://github.com/benny123tw/eslint-config",
"license": "MIT",
"main": "index.cjs",
"homepage": "https://github.com/benny123tw/eslint-config",
"repository": "https://github.com/benny123tw/eslint-config.git",
"keywords": [
"eslint-config"
],
"exports": {
".": "./index.cjs"
},
"main": "index.cjs",
"files": [
"index.cjs"
],
"peerDependencies": {
"eslint": ">=8.44.0",
"typescript": ">=3.9"
},
"dependencies": {
"@rushstack/eslint-patch": "^1.3.2",
"@typescript-eslint/eslint-plugin": "^5.59.11",
"@typescript-eslint/parser": "^5.59.11",
"@benny123tw/prettier-config": "workspace:^",
"eslint-plugin-vue": "^9.14.1",
"typescript": "^5.1.3",
"eslint-config-prettier": "^8.9.0",
"eslint-plugin-prettier": "^5.0.0"
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/eslint-plugin": "^6.4.1",
"@typescript-eslint/parser": "^6.4.1",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-vue": "^9.17.0",
"typescript": "^5.2.2"
},
"devDependencies": {
"@types/eslint": "^8.40.2",
"eslint": "^8.43.0"
},
"peerDependencies": {
"eslint": ">=7.4.0",
"typescript": ">=3.9"
"@types/eslint": "^8.44.2",
"eslint": "^8.47.0"
}
}
2 changes: 1 addition & 1 deletion packages/eslint-config/test/basic.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'node:url'
import { it, expect, describe } from 'vitest'
import { describe, expect, it } from 'vitest'
import { ESLint } from 'eslint'

describe('eslint-config', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/prettier-config/index.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @type {import('prettier').Options} */
const config = {
semi: false,
singleQuote: true,
tabWidth: 2,
printWidth: 100
semi: false,
singleQuote: true,
tabWidth: 2,
printWidth: 100,
}

module.exports = config;
module.exports = config
1 change: 1 addition & 0 deletions packages/prettier-config/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare const config: import('prettier').Options
13 changes: 7 additions & 6 deletions packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
"version": "0.0.2",
"description": "Prettier config for Benny personal usage",
"author": "Benny Yen <benny123tw@gmail.com>",
"repository": "https://github.com/benny123tw/eslint-config.git",
"homepage": "https://github.com/benny123tw/eslint-config",
"license": "MIT",
"main": "index.cjs",
"homepage": "https://github.com/benny123tw/eslint-config",
"repository": "https://github.com/benny123tw/eslint-config.git",
"exports": {
".": "./index.cjs"
},
"main": "index.cjs",
"types": "index.d.ts",
"files": [
"index.cjs"
],
"devDependencies": {
"prettier": "^3.0.0"
},
"peerDependencies": {
"prettier": ">= 3.0.0"
},
"devDependencies": {
"prettier": "^3.0.2"
}
}
Loading

0 comments on commit ba52938

Please sign in to comment.