title: How to fix "Found fs.readFile with non literal argument at index 0"?
body: <p>I am trying to add <a href="https://github.com/nodesecurity/eslint-plugin-security" rel="noreferrer">eslint-plugin-security</a> in a TypeScript project. However, for these codes</p>
  <pre><code>import { promises as fsp } from 'fs';
  import fs from 'fs';
  import path from 'path';
  
  const index = await fsp.readFile(path.resolve(__dirname, './index.html'), 'utf-8');
  const key = fs.readFileSync(path.join(__dirname, './ssl.key'));
  await fsp.writeFile(path.resolve(__dirname, './sitemap.xml'), sitemap);
  </code></pre>
  <p>I got many these ESLint warnings:</p>
  <blockquote>
  <pre><code>warning Found fs.readFile with non literal argument at index 0   security/detect-non-literal-fs-filename
  warning Found fs.readFileSync with non literal argument at index 0  security/detect-non-literal-fs-filename
  warning Found fs.writeFile with non literal argument at index 0  security/detect-non-literal-fs-filename
  </code></pre>
  </blockquote>
  <p>I found the document about this ESLint error at <a href="https://github.com/nodesecurity/eslint-plugin-security#detect-non-literal-fs-filename" rel="noreferrer">https://github.com/nodesecurity/eslint-plugin-security#detect-non-literal-fs-filename</a></p>
  <p>But I still have no idea how to fix it. Any guide will be helpful! Thanks</p>
  <hr />
  <p><strong>UPDATE</strong>:</p>
  <p>Found out as long as using passing the path returned by <code>path.join</code> or <code>path.resolve</code> will show this ESLint issue.</p>
  <p>If I change to absolute path, the ESLint issue is gone. However, this loose the benefit of the relative path by <code>path.join</code> or <code>path.resolve</code>.</p>
  <pre><code>fs.readFileSync('/Users/me/project/ssl.key');
  </code></pre>
  <p>Looking for an alternative / better way if exists.</p>
  <p>(Might be a false alarm? Asked at <a href="https://github.com/nodesecurity/eslint-plugin-security/issues/65" rel="noreferrer">https://github.com/nodesecurity/eslint-plugin-security/issues/65</a>)</p>