Skip to content

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
@thernstig
Copy link

@ota-meshi am I missing something, or should this PR in reality have fixed something like:

      const scriptDirectory = import.meta.dirname;
      const outputDirectoryPath = path.resolve(scriptDirectory, 'output');
      await fs.mkdir(outputDirectoryPath, { recursive: true });

@ota-meshi
Copy link
Member Author

import.meta.dirname did not exist at the time this PR was opened.
If you would like support for it, please open an issue and a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False alarm for “Found fs.readFile with non literal argument at index 0”? Should __dirname be ignored in detect-non-literal-require?

4 participants