Skip to content

Commit

Permalink
feat(eslint-plugin): support to ts on the codebase + new consistent-p…
Browse files Browse the repository at this point in the history
…rops-type rule
  • Loading branch information
gtkatakura committed Apr 29, 2024
1 parent bec549e commit d9369f0
Show file tree
Hide file tree
Showing 23 changed files with 5,069 additions and 288 deletions.
2 changes: 2 additions & 0 deletions packages/eslint-plugin-vtex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# package build
dist
2 changes: 2 additions & 0 deletions packages/eslint-plugin-vtex/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- `vtex/consistent-props-type` rule

## [2.2.1] - 2022-05-30
### Added
Expand Down
11 changes: 0 additions & 11 deletions packages/eslint-plugin-vtex/index.js

This file was deleted.

9 changes: 0 additions & 9 deletions packages/eslint-plugin-vtex/lib/includes/getDocUrl.js

This file was deleted.

84 changes: 0 additions & 84 deletions packages/eslint-plugin-vtex/lib/rules/prefer-early-return.js

This file was deleted.

This file was deleted.

36 changes: 30 additions & 6 deletions packages/eslint-plugin-vtex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
"name": "eslint-plugin-vtex",
"version": "2.2.1",
"description": "VTEX's ESLint plugin",
"main": "index.js",
"main": "dist/eslint-plugin-vtex.cjs.js",
"module": "dist/eslint-plugin-vtex.esm.js",
"types": "dist/eslint-plugin-vtex.cjs.d.ts",
"files": [
"index.js",
"lib/"
"docs",
"dist"
],
"license": "MIT",
"bugs": {
Expand All @@ -18,27 +20,49 @@
"directory": "packages/eslint-plugin-vtex"
},
"contributors": [
"Christian Kaisermann <christian.andrade@vtex.com.br>"
"Christian Kaisermann <christian.andrade@vtex.com.br>",
"Gabriel Takashi Katakura <gabriel.katakura@vtex.com.br>"
],
"keywords": [
"eslint",
"eslint-plugin",
"vtex"
],
"scripts": {
"version": "chan release $npm_package_version && git add CHANGELOG.md",
"watch": "tsdx watch",
"build": "tsdx build",
"test": "jest",
"version": "chan release $npm_package_version && git add CHANGELOG.md"
"lint": "tsdx lint",
"prepare": "tsdx build"
},
"jest": {
"transform": {
"\\.(js|ts)$": [
"babel-jest",
{
"configFile": "./test/babel.config.js"
}
]
},
"testPathIgnorePatterns": [
"/node_modules/"
],
"collectCoverage": false
},
"dependencies": {
"@typescript-eslint/utils": "^5.15.0"
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/preset-env": "^7.24.4",
"@babel/preset-typescript": "^7.24.1",
"@types/eslint": "^8.56.10",
"@typescript-eslint/experimental-utils": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"jest": "^27.5.1"
"babel-jest": "^29.7.0",
"jest": "^27.5.1",
"tsdx": "^0.14.1"
},
"peerDependencies": {
"eslint": "^6 || ^7 || ^8"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import type { Linter } from 'eslint'

export const recommended: Linter.BaseConfig = {
rules: {
// Prefer an early return to prevent nesting and improve code readability.
'vtex/prefer-early-return': [
Expand All @@ -7,5 +9,7 @@ module.exports = {
maxStatements: 2,
},
],

'vtex/consistent-props-type': 'warn',
},
}
6 changes: 6 additions & 0 deletions packages/eslint-plugin-vtex/src/createRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ESLintUtils } from '@typescript-eslint/utils'

export const createRule = ESLintUtils.RuleCreator(
(name) =>
`https://github.com/vtex/typescript/tree/main/packages/eslint-plugin-vtex/docs/${name}.md`
)
22 changes: 22 additions & 0 deletions packages/eslint-plugin-vtex/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { recommended } from './configs/recommended'
import { consistentPropsType } from './rules/consistent-props-type'
import { preferEarlyReturn } from './rules/prefer-early-return'
import { preferUseEffectNamedCallback } from './rules/prefer-use-effect-named-callback'

// tsdx doesn't support we configure our tsconfig.json
// to target module commonjs, so we need to manually
// use module.exports here
module.exports = {
configs: {
recommended,
},

// TODO: these rules could be auto-generated using fs+path,
// but tsdx doesn't works well with dynamic imports,
// so we need to change our build system first
rules: {
'consistent-props-type': consistentPropsType,
'prefer-early-return': preferEarlyReturn,
'prefer-use-effect-named-callback': preferUseEffectNamedCallback,
},
}
Loading

0 comments on commit d9369f0

Please sign in to comment.