Skip to content

Commit

Permalink
feat(core): support for v9 configs (#53)
Browse files Browse the repository at this point in the history
* feat(core): support for v9 configs

* ci: add versioned testing

* ci: fix install command

* ci: fix install

* fix: add backward compat parser config

* fix: scope context
  • Loading branch information
barelyhuman authored Nov 11, 2024
1 parent f18e602 commit 50aae4b
Show file tree
Hide file tree
Showing 6 changed files with 1,123 additions and 2,020 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/cache@v1
id: cache-build
with:
path: "."
path: '.'
key: ${{ github.sha }}

lint:
Expand All @@ -27,17 +27,30 @@ jobs:
- uses: actions/cache@v1
id: restore-build
with:
path: "."
path: '.'
key: ${{ github.sha }}
- run: yarn eslint:ci

test:
name: Test
strategy:
matrix:
eslint: [8.x, '9.x']
node: [18.x, 20.x, 22.x, 23.x]
runs-on: ubuntu-latest
needs: build
timeout-minutes: 30
steps:
- uses: actions/cache@v1
id: restore-build
- name: Checkout
uses: actions/checkout@v4
with:
path: "."
key: ${{ github.sha }}
- run: yarn test
fetch-depth: 1
- name: Install Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install Packages
run: yarn install --check-files
- name: Install ESLint ${{ matrix.eslint }}
run: yarn add --no-lockfile eslint@${{ matrix.eslint }}
- name: Test
run: yarn test
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"devDependencies": {
"@babel/core": "^7.17.9",
"@babel/eslint-parser": "^7.17.0",
"@babel/eslint-parser": "^7.25.9",
"@babel/preset-env": "^7.16.11",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-node-resolve": "^13.2.0",
Expand All @@ -94,11 +94,12 @@
"eslint-plugin-jest": "^26.1.4",
"eslint-plugin-prettier": "^4.0.0",
"husky": ">=7",
"jest": "^26.5.2",
"jest": "^29.4.2",
"json": "^11.0.0",
"lint-staged": ">=10",
"prettier": "^2.6.2",
"rollup": "^2.70.1",
"semver": "^7.6.3",
"shx": "^0.3.4"
}
}
8 changes: 7 additions & 1 deletion src/StateSnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ export default {
},
},
create(context) {
// FIX: remove when dropping support for < v9
var sourceCode = context.sourceCode || context.getSourceCode()
var getScope =
'getScope' in context
? context.getScope.bind(context)
: sourceCode.getScope.bind(sourceCode)
return {
Identifier(node) {
const scope = context.getScope(node)
const scope = getScope(node)

if (isInComputed(node) && isInProperty(node)) {
if (
Expand Down
33 changes: 23 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import StateSnapshot from './StateSnapshot'
import AvoidThisInProxy from './AvoidThisInProxy'

export const rules = {
'state-snapshot-rule': StateSnapshot,
'avoid-this-in-proxy': AvoidThisInProxy,
const plugin = {
meta: {
name: 'eslint-plugin-valtio',
},
rules: {
'state-snapshot-rule': StateSnapshot,
'avoid-this-in-proxy': AvoidThisInProxy,
},
configs: {},
}

export const configs = {
recommended: {
plugins: ['valtio'],
rules: {
'valtio/state-snapshot-rule': 'warn',
'valtio/avoid-this-in-proxy': 'warn',
Object.assign(plugin, {
configs: {
recommended: {
plugins: { valtio: plugin },
rules: {
'valtio/state-snapshot-rule': 'warn',
'valtio/avoid-this-in-proxy': 'warn',
},
},
},
}
})

module.exports = plugin

export const configs = plugin.configs
export const rules = plugin.rules
30 changes: 30 additions & 0 deletions tests/parser-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
const eslintVersion = require('eslint/package.json').version
const semver = require('semver')

export function getParserConfig() {
if (semver.satisfies(eslintVersion, '>=9')) {
return getEslintv9Config()
}
return getEslintv8Config()
}

function getEslintv9Config() {
return {
languageOptions: {
parser: require('@babel/eslint-parser'),
ecmaVersion: 6,
sourceType: 'module',
parserOptions: {
requireConfigFile: false,
babelOptions: {
babelrc: false,
configFile: false,
parserOpts: {
plugins: ['jsx'],
},
},
},
},
}
}

function getEslintv8Config() {
return {
parserOptions: {
requireConfigFile: false,
Expand Down
Loading

0 comments on commit 50aae4b

Please sign in to comment.