Skip to content

Commit

Permalink
style: Tighten eslint rules (#775)
Browse files Browse the repository at this point in the history
* Tighten eslint rules

* Bump node in github actions to 18
  • Loading branch information
robbie-c authored Aug 18, 2023
1 parent e69e488 commit 229a94d
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 109 deletions.
62 changes: 34 additions & 28 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
/*eslint-env node */

const rules = {
'prettier/prettier': 'error',
'prefer-spread': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['error'],
'no-prototype-builtins': 'off',
'no-empty': 'off',
}

const extend = [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'prettier',
'plugin:compat/recommended',
]

module.exports = {
env: {
browser: true,
es6: true,
'jest/globals': true,
},
globals: {
given: 'readonly',
global: 'readonly',
Buffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['prettier', '@typescript-eslint', 'eslint-plugin-react', 'eslint-plugin-react-hooks'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'prettier',
'plugin:compat/recommended',
],
rules: {
'prettier/prettier': 'error',
'prefer-spread': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
plugins: ['prettier', '@typescript-eslint', 'eslint-plugin-react', 'eslint-plugin-react-hooks', 'jest'],
extends: extend,
rules,
settings: {
react: {
version: '17.0',
Expand All @@ -34,19 +50,9 @@ module.exports = {
// the same set of config as in the root
// but excluding the 'plugin:compat/recommended' rule
// we don't mind using the latest features in our tests
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'prettier',
],
rules: {
'prettier/prettier': 'error',
'prefer-spread': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
extends: extend.filter((s) => s !== 'plugin:compat/recommended'),
rules,
},
],
root: true,
}
6 changes: 3 additions & 3 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
fetch-depth: 0
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}

- name: Set up Node 14
uses: actions/setup-node@v2
- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
registry-url: https://registry.npmjs.org

- name: Install dependencies
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/library-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# Install Node.js
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'yarn'

# Install your dependencies
Expand All @@ -33,7 +33,8 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
cache: 'yarn'

- run: yarn install && yarn build

Expand All @@ -50,7 +51,7 @@ jobs:
# Install Node.js
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'yarn'

# Install your dependencies
Expand All @@ -68,7 +69,7 @@ jobs:
# Install Node.js
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'yarn'

# Install your dependencies
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/react.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'yarn'
- run: yarn && yarn build && cd react && yarn test
6 changes: 4 additions & 2 deletions .github/workflows/ssr-es-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
cache: 'yarn'


- run: yarn install && yarn build

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/testcafe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ jobs:
- name: Check out posthog-js
uses: actions/checkout@v2

- name: Set up Node 14
uses: actions/setup-node@v2
- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18

- name: Serve static files
run: python -m http.server 8080 &
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@
"@types/jest": "^29.5.1",
"@types/react-dom": "^18.0.10",
"@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"babel-eslint": "10.1.0",
"babel-jest": "^26.6.3",
"cypress": "10.3.1",
"eslint": "8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-compat": "^4.1.4",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-react-hooks": "^4.6.0",
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/extensions/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ describe('Toolbar', () => {
})

it('should initialize the toolbar when there are editor params in the session', () => {
given('storedEditorParams', () => JSON.stringify(toolbarParams))

given.subject()
expect(given.toolbar.loadToolbar).toHaveBeenCalledWith({
...given.toolbarParams,
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/posthog-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ describe('init()', () => {
delete window.rrwebRecord
window.rrwebRecord = 'is possible'
given.subject()
expect(given.lib.__loaded_recorder_version).toMatch(new RegExp(`^1\.?`)) // start with 1.?.?
expect(given.lib.__loaded_recorder_version).toMatch(/^1\./) // start with 1.?.?
})

it('set __loaded_recorder_version flag to v1 if recording script has been included', () => {
Expand All @@ -611,7 +611,7 @@ describe('init()', () => {
delete window.rrwebRecord
window.rrwebRecord = 'is possible'
given.subject()
expect(given.lib.__loaded_recorder_version).toMatch(new RegExp(`^2\.?`)) // start with 2.?.?
expect(given.lib.__loaded_recorder_version).toMatch(/^2\./) // start with 2.?.?
})

it('does not load autocapture, feature flags, toolbar, session recording or compression', () => {
Expand Down Expand Up @@ -661,8 +661,8 @@ describe('init()', () => {

expect(given.lib.register_once).toHaveBeenCalledWith(
{
$device_id: truth((val) => val.match(/^[0-9a-f\-]+$/)),
distinct_id: truth((val) => val.match(/^[0-9a-f\-]+$/)),
$device_id: truth((val) => val.match(/^[0-9a-f-]+$/)),
distinct_id: truth((val) => val.match(/^[0-9a-f-]+$/)),
},
''
)
Expand All @@ -686,8 +686,8 @@ describe('init()', () => {

expect(given.lib.register_once).toHaveBeenCalledWith(
{
$device_id: truth((val) => val.match(/^custom\-[0-9a-f]+/)),
distinct_id: truth((val) => val.match(/^custom\-[0-9a-f]+/)),
$device_id: truth((val) => val.match(/^custom-[0-9a-f]+/)),
distinct_id: truth((val) => val.match(/^custom-[0-9a-f]+/)),
},
''
)
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/sessionrecording-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function ensureMaxMessageSize(data: eventWithTime): { event: eventWithTim
// 1) Checks if the pattern starts with 'data:' (potentially, not at the start of the string)
// 2) Extracts the mime type of the data uri in the first group
// 3) Determines when the data URI ends.Depending on if it's used in the src tag or css, it can end with a ) or "
const dataURIRegex = /data:([\w\/\-\.]+);(\w+),([^)"]*)/gim
const dataURIRegex = /data:([\w/\-.]+);(\w+),([^)"]*)/gim
const matches = stringifiedData.matchAll(dataURIRegex)
for (const match of matches) {
if (match[1].toLocaleLowerCase().slice(0, 6) === 'image/') {
Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Config from './config'
import { Breaker, EventHandler, Properties } from './types'
import { uuidv7 } from './uuidv7'

/*
* Saved references to long variable names, so that closure compiler can
Expand Down
Loading

0 comments on commit 229a94d

Please sign in to comment.