Skip to content

standard.lintFiles() doesn't use process.cwd() #1956

Open
standard/standard-engine
#329
@regseb

Description

@regseb

Here's what I did

Files

  • package.json

    {
      "name": "testcase",
      "version": "1.0.0",
      "type": "module",
      "dependencies": {
        "standard": "17.1.0"
      }
    }
  • index.js

    import fs from "node:fs/promises";
    import process from "node:process";
    import standard from "standard";
    
    console.log(await fs.readFile("foo/bar.js", "utf8"));
    console.log(await standard.lintFiles(["foo/bar.js"]));
    
    process.chdir("foo");
    console.log(await fs.readFile("bar.js", "utf8"));
    console.log(await standard.lintFiles(["bar.js"]));
  • foo/bar.js

    var baz = 'qux'

Steps

  1. npm install
  2. node index.js

What I expected to happen

var baz = 'qux'

[
  {
    filePath: '/home/regseb/testcase/foo/bar.js',
    messages: [ [Object], [Object] ],
    suppressedMessages: [],
    errorCount: 1,
    fatalErrorCount: 0,
    warningCount: 1,
    fixableErrorCount: 0,
    fixableWarningCount: 1,
    source: "var baz = 'qux'\n",
    usedDeprecatedRules: [Getter]
  }
]
var baz = 'qux'


[
  {
    filePath: '/home/regseb/testcase/foo/bar.js',
    messages: [ [Object], [Object] ],
    suppressedMessages: [],
    errorCount: 1,
    fatalErrorCount: 0,
    warningCount: 1,
    fixableErrorCount: 0,
    fixableWarningCount: 1,
    source: "var baz = 'qux'\n",
    usedDeprecatedRules: [Getter]
  }
]

What seems to have happened

var baz = 'qux'

[
  {
    filePath: '/home/regseb/testcase/foo/bar.js',
    messages: [ [Object], [Object] ],
    suppressedMessages: [],
    errorCount: 1,
    fatalErrorCount: 0,
    warningCount: 1,
    fixableErrorCount: 0,
    fixableWarningCount: 1,
    source: "var baz = 'qux'\n",
    usedDeprecatedRules: [Getter]
  }
]
var baz = 'qux'

/home/regseb/testcase/node_modules/eslint/lib/cli-engine/file-enumerator.js:320
                    throw new NoFilesFoundError(
                          ^

NoFilesFoundError: No files matching 'bar.js' were found.
    at FileEnumerator.iterateFiles (/home/regseb/testcase/node_modules/eslint/lib/cli-engine/file-enumerator.js:320:27)
    at iterateFiles.next (<anonymous>)
    at CLIEngine.executeOnFiles (/home/regseb/testcase/node_modules/eslint/lib/cli-engine/cli-engine.js:797:48)
    at ESLint.lintFiles (/home/regseb/testcase/node_modules/eslint/lib/eslint/eslint.js:551:23)
    at StandardEngine.lintFiles (/home/regseb/testcase/node_modules/standard-engine/index.js:89:41)
    at file:///home/regseb/testcase/index.js:11:28 {
  messageTemplate: 'file-not-found',
  messageData: { pattern: 'bar.js', globDisabled: false }
}

Node.js v20.10.0

Standard doesn't use the current directory. It uses the current directory when importing "standard":

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions