Skip to content

Commit

Permalink
chore: custom lint rules (#18206)
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin authored and Gilbert09 committed Oct 30, 2023
1 parent 72b7672 commit 3e0dca3
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 5 deletions.
20 changes: 18 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ module.exports = {
react: {
version: 'detect',
},
'import/resolver': {
node: {
paths: ['eslint-rules'], // Add the directory containing your custom rules
extensions: ['.js', '.jsx', '.ts', '.tsx'], // Ensure ESLint resolves both JS and TS files
},
},
},
extends: [
'eslint:recommended',
Expand All @@ -37,7 +43,7 @@ module.exports = {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['prettier', 'react', 'cypress', '@typescript-eslint', 'no-only-tests', 'jest', 'compat'],
plugins: ['prettier', 'react', 'cypress', '@typescript-eslint', 'no-only-tests', 'jest', 'compat', 'posthog'],
rules: {
'no-console': ['error', { allow: ['warn', 'error'] }],
'no-debugger': 'error',
Expand Down Expand Up @@ -91,7 +97,7 @@ module.exports = {
],
},
],
'react/forbid-elements': [
'posthog/warn-elements': [
1,
{
forbid: [
Expand Down Expand Up @@ -236,6 +242,16 @@ module.exports = {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: 'eslint-rules/**/*',
extends: ['eslint:recommended'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
env: {
node: true,
},
},
],
reportUnusedDisableDirectives: true,
}
3 changes: 3 additions & 0 deletions eslint-rules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# PostHog Custom ESLint rules

This package contains custom ESLint rules for PostHog's codebase.
10 changes: 10 additions & 0 deletions eslint-rules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { readdirSync } = require('fs')
const { basename } = require('path')

const ruleFiles = readdirSync('eslint-rules').filter(
(file) => file.endsWith('.js') && file !== 'index.js' && !file.endsWith('test.js')
)

const rules = Object.fromEntries(ruleFiles.map((file) => [basename(file, '.js'), require('./' + file)]))

module.exports = { rules }
3 changes: 3 additions & 0 deletions eslint-rules/warn-elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { rules } = require('eslint-plugin-react')

module.exports = rules['forbid-elements']
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-insights--user-paths-edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions frontend/src/lib/components/PayGateMini/PayGateMini.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ export function PayGateMini({
<div className="PayGateMini__icon">{featureSummary.icon || <IconPremium />}</div>
<div className="PayGateMini__description">{featureSummary.description}</div>
<div className="PayGateMini__cta">
Subscribe to gain {featureSummary.umbrella}.
Subscribe to gain {featureSummary.umbrella}.
{featureSummary.docsHref && (
<>
{' '}
<a href={featureSummary.docsHref} target="_blank" rel="noopener noreferrer">
Learn more in PostHog Docs.
Learn more in PostHog Docs.
</a>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-jest": "^27.4.3",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-posthog": "link:./eslint-rules",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-storybook": "^0.6.15",
Expand Down
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit 3e0dca3

Please sign in to comment.