Skip to content
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

fix: false positives for static expressions in detect-non-literal-fs-filename, detect-child-process, detect-non-literal-regexp, and detect-non-literal-require #109

Merged
merged 3 commits into from Feb 2, 2023

Conversation

ota-meshi
Copy link
Member

@ota-meshi ota-meshi commented Jan 12, 2023

This PR improves 4 rules and changes them to track the expression used and not report when it is a static value.

They will no longer be reported after the change in this PR.

import fs from 'fs';
import path from 'path';
const html = fs.readFileSync(path.resolve(__dirname, './index.html'), 'utf-8');
                          // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

import url from "url";
const dirname = path.dirname(url.fileURLToPath(import.meta.url));
const html = fs.readFileSync(path.resolve(dirname, './index.html'), 'utf-8');
                          // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

const pkg = fs.readFileSync(require.resolve('eslint/package.json'), 'utf-8');
                         // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

const config = require(process.cwd() + '/foo.config.js');
                    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

import child_process from 'child_process';
const FOO = 'ls';
child_process.exec(FOO);
                // ^^^

const source = 'ab+c'
const a = new RegExp(source, 'i')
                  // ^^^^^^

close #65
close #49
related to #22

@ota-meshi ota-meshi changed the title fix(detect-non-literal-fs-filename, detect-child-process, detect-non-literal-regexp, detect-non-literal-require): false positives for static expressions fix(detect-non-literal-fs-filename,detect-child-process,detect-non-literal-regexp,detect-non-literal-require): false positives for static expressions Jan 12, 2023
@ota-meshi ota-meshi changed the title fix(detect-non-literal-fs-filename,detect-child-process,detect-non-literal-regexp,detect-non-literal-require): false positives for static expressions fix: false positives for static expressions in detect-non-literal-fs-filename, detect-child-process, detect-non-literal-regexp, and detect-non-literal-require Jan 12, 2023
@ota-meshi ota-meshi force-pushed the issue65 branch 7 times, most recently from 1479889 to 6dfa9c4 Compare January 16, 2023 01:25
@nzakas
Copy link
Contributor

nzakas commented Jan 26, 2023

#108 has been merged.

…filename, detect-child-process, detect-non-literal-regexp, and detect-non-literal-require
@ota-meshi ota-meshi marked this pull request as ready for review January 27, 2023 00:05
@ota-meshi ota-meshi requested a review from a team January 27, 2023 00:05
@ota-meshi
Copy link
Member Author

I have rebased this PR!

Copy link
Contributor

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@nzakas nzakas merged commit 56102b5 into main Feb 2, 2023
@nzakas nzakas deleted the issue65 branch February 2, 2023 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants