-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin-internal): [no-dynamic-tests] new internal Lint rule to ban dynamic syntax in generating tests #11323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR, @nayounsang! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
View your CI Pipeline Execution ↗ for commit e668354
☁️ Nx Cloud last updated this comment at |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11323 +/- ##
==========================================
- Coverage 90.86% 90.86% -0.01%
==========================================
Files 503 504 +1
Lines 51036 51161 +125
Branches 8424 8456 +32
==========================================
+ Hits 46373 46485 +112
- Misses 4648 4661 +13
Partials 15 15
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! Only the one request for an added test is blocking IMO. Everything else is nitpicks that can be ignored if you don't like them. 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥 thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if we intend to use this ever, we should enable it already now for all the files that don't currently have violations. (Maybe even this is a good chance for us to try out the eslint bulk suppressions feature)?
Also, please do enable the rule on the codebase and have a look at the reports to see whether they make sense and would make sense to a contributor.
Thanks!
prop.value.elements.forEach(element => { | ||
if (element && isDynamicExpression(element)) { | ||
context.report({ | ||
node: element, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than reporting on the whole object expression, let's report on the specific offending node(s). The closer the report is to the issue, the the easier it is for a user to understand what's wrong and how to fix it.
For example, in no-relative-paths-to-internal-packages
, we should report like this
{
code: "import packageJson from '../../package.json' with { type: 'json' };",
filename: path.resolve(PACKAGES_DIR, 'ast-spec/vitest.config.mts'),
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
},
rather than the entire object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice review. I committed. I made it so that recursive functions report on elements rather than returning whether they are dynamic.
ChangeAs In the interest of the current issue and in my opinion, I enable dynamic object value. // ex
{
output: getOutput()
}
However, the code and error properties are excluded as an exception. These two properties often make analysis difficult when dynamically allocated. +1
So, I fix and test it. |
Probably if CI is run again, there will be no prob: Docusaurus can't find @typescript-eslint/eslint-plugin. This PR has nothing to do with this failure. This is my first time using This is perf comparison for # with suppressions
=== result ===
total time: 55.0sec
max CPU: 109.1%
avg CPU: 1.37%
max Memory: 1.0%
avg Memory: .30%
max RSS: 168256KB
avg RSS: 49736.64KB
=== result ===
total time: 52.0sec
max CPU: 90.4%
avg CPU: 1.44%
max Memory: 1.0%
avg Memory: .28%
max RSS: 167744KB
avg RSS: 46318.16KB
# without suppressions
=== result ===
total time: 57.0sec
max CPU: 114.0%
avg CPU: 1.50%
max Memory: 1.0%
avg Memory: .26%
max RSS: 167952KB
avg RSS: 43129.38KB
=== result ===
total time: 52.0sec
max CPU: 85.1%
avg CPU: 1.29%
max Memory: 1.0%
avg Memory: .31%
max RSS: 171712KB
avg RSS: 52057.46KB Monitor with this sh: #!/bin/bash
start=$(date +%s.%N)
# RUN
yarn nx lint eslint-plugin --skip-nx-cache > /dev/null 2>&1 &
pid=$!
# Variables
max_cpu=0; max_mem=0; max_rss=0
total_cpu=0; total_mem=0; total_rss=0
sample_count=0
# Monitor
while true; do
if ! kill -0 $pid 2>/dev/null; then
break
fi
ps_info=$(ps -p $pid -o %cpu,%mem,rss 2>/dev/null | tail -1)
if [ ! -z "$ps_info" ] && [ "$ps_info" != "%CPU" ]; then
cpu=$(echo "$ps_info" | awk '{print $1}')
mem=$(echo "$ps_info" | awk '{print $2}')
rss=$(echo "$ps_info" | awk '{print $3}')
# isNumber?
if [[ "$cpu" =~ ^[0-9]+\.?[0-9]*$ ]] && [[ "$mem" =~ ^[0-9]+\.?[0-9]*$ ]] && [[ "$rss" =~ ^[0-9]+$ ]]; then
[ $(echo "$cpu > $max_cpu" | bc -l) -eq 1 ] && max_cpu=$cpu
[ $(echo "$mem > $max_mem" | bc -l) -eq 1 ] && max_mem=$mem
[ $(echo "$rss > $max_rss" | bc -l) -eq 1 ] && max_rss=$rss
total_cpu=$(echo "$total_cpu + $cpu" | bc -l)
total_mem=$(echo "$total_mem + $mem" | bc -l)
total_rss=$(echo "$total_rss + $rss" | bc -l)
sample_count=$((sample_count + 1))
fi
fi
sleep 0.5
done
wait $pid
end=$(date +%s.%N)
time=$(echo "$end - $start" | bc -l)
if [ $sample_count -gt 0 ]; then
avg_cpu=$(echo "scale=2; $total_cpu / $sample_count" | bc -l)
avg_mem=$(echo "scale=2; $total_mem / $sample_count" | bc -l)
avg_rss=$(echo "scale=2; $total_rss / $sample_count" | bc -l)
else
avg_cpu=0
avg_mem=0
avg_rss=0
fi
echo ""
echo ""
echo "=== result ==="
echo "total time: ${time}sec"
echo "max CPU: ${max_cpu}%"
echo "avg CPU: ${avg_cpu}%"
echo "max Memory: ${max_mem}%"
echo "avg Memory: ${avg_mem}%"
echo "max RSS: ${max_rss}KB"
echo "avg RSS: ${avg_rss}KB"
|
PR Checklist
Overview
no-dynamic-tests
Ban these:
For test case object, It validate these keys recursively:
code
,error
.No checks are performed on other keys.
Applied the rules to the test file in
eslint-plugin
&eslint-plugin-internal
. Bulk suppression feature was applied.Create the script to update suppression.