Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/compare-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Compare PR

on:
issue_comment:
types: [created, edited]

jobs:
compare:
runs-on: ubuntu-latest
if: contains(github.event.comment.body, '@github-actions eslint-remote-tester compare')
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.11
- uses: AriPerkkio/eslint-remote-tester-compare-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
allowed-associations: '["OWNER", "COLLABORATOR"]'
max-result-count: 100
eslint-remote-tester-config: test/eslint-remote-tester.config.js
repository-initialize-command: |
npm install
npm link
npm link eslint-plugin-react
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ node_modules
!tests/**/node_modules
npm-debug.log
sftp-config.json
eslint-remote-tester-results
.cache-eslint-remote-tester

# Only apps should have lockfiles
yarn.lock
Expand Down
25 changes: 20 additions & 5 deletions lib/rules/jsx-max-depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const variableUtil = require('../util/variable');
const jsxUtil = require('../util/jsx');
const docsUrl = require('../util/docsUrl');

function includes(array, item) {
return !!array.some((i) => i === item);
}

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -83,8 +87,8 @@ module.exports = {
});
}

function findJSXElementOrFragment(variables, name) {
function find(refs) {
function findJSXElementOrFragment(variables, name, previousReferences) {
function find(refs, prevRefs) {
let i = refs.length;

while (--i >= 0) {
Expand All @@ -94,15 +98,26 @@ module.exports = {
return (jsxUtil.isJSX(writeExpr)
&& writeExpr)
|| ((writeExpr && writeExpr.type === 'Identifier')
&& findJSXElementOrFragment(variables, writeExpr.name));
&& findJSXElementOrFragment(variables, writeExpr.name, prevRefs));
}
}

return null;
}

const variable = variableUtil.getVariable(variables, name);
return variable && variable.references && find(variable.references);
if (variable && variable.references) {
const containDuplicates = previousReferences.some((ref) => includes(variable.references, ref));

// Prevent getting stuck in circular references
if (containDuplicates) {
return false;
}

return find(variable.references, previousReferences.concat(variable.references));
}

return false;
}

function checkDescendant(baseDepth, children) {
Expand Down Expand Up @@ -141,7 +156,7 @@ module.exports = {
}

const variables = variableUtil.variablesInScope(context);
const element = findJSXElementOrFragment(variables, node.expression.name);
const element = findJSXElementOrFragment(variables, node.expression.name, []);

if (element) {
const baseDepth = getDepth(node);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-eslint-plugin": "^2.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-remote-tester": "^1.1.0",
"espree": "^3.5.4",
"istanbul": "^0.4.5",
"markdown-magic": "^1.0.0",
Expand Down
63 changes: 63 additions & 0 deletions test/eslint-remote-tester.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'use strict';

const repositories = require('./repositories.json').slice(0, 500);

module.exports = {
repositories,

extensions: ['js', 'jsx', 'ts', 'tsx'],

pathIgnorePattern: `(${[
'node_modules',
'\\/\\.', // Any file or directory starting with dot, e.g. ".git"
'/dist/',
'/build/',

// Minified JS committed to remote
'codesandbox-client/packages/app/static/js',
'codesandbox-client/standalone-packages',
'dockunit/platform/assets',
'hyper/bin',
'react-solitaire/lib/index\\.js',
'babel\\.js',
'chunk\\.js',
'bundle\\.js',
'react-dom\\.development\\.js',
'vendor\\.min\\.js',
'\\.min\\.js', // Any *.min.js
'/public/',

'Khan/perseus/lib',
'glortho/react-keydown/example/public',
'reach/reach-ui/packages/combobox/examples/cities\\.ts',
'reach/reach-ui/website/src/components/cities\\.js',
'reach/reach-ui/website/static/router/static',
'Automattic/wp-calypso/client/components/phone-input/data\\.js',
'test262-main\\.ts',
'sample_vis\\.test\\.mocks\\.ts',
'flow-typed'
].join('|')})`,

concurrentTasks: 3,

eslintrc: {
root: true,
env: {
es6: true
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
settings: {
react: {
version: '16.13.1'
}
},
plugins: ['react']
}
};
Loading