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
Bug: FlatArrayConfig options cannot be overriden #17669
Comments
This is be design. |
I'm instanciating const linter = new Linter({
configType: "flat",
});
const filename = '/tmp/myfile.ts';
const report = linter.verifyAndFix(code, config, filename); But In my specific case I found out that I can just pass You can check full usage here https://github.com/batijs/bati/blob/92b3745621fe21483508b16908136861733945dc/packages/core/src/parse/linters/common.ts#L12 Replacing |
I don't think that's what's going on here. |
Indeed it does. But the behaviour is unexpected with a leading |
Happy to add something to the docs. Where would you expect to find that note? |
I guess in https://eslint.org/docs/latest/integrate/nodejs-api#linterverify on |
Would you be interested in sending a PR for that? |
Yes I could help with that, but I would first need to know how to properly describe the current behaviour, because it still seems odd after testing a little more. Take a look at https://stackblitz.com/edit/stackblitz-starters-byefgh?file=index.js |
The That said, it does seem strange that |
Okay, so I figured out what is going on. This is a behavior inside of Node.js, specifically, inside of console.log(path.relative("", process.cwd())); // outputs ""
console.log(path.relative("", "/foo/bar")); // outputs "..\..\..\..\..\foo\bar" From looking at the Node.js code, it looks like So what we probably want to do is just skip the |
In Node.js, `path.relative("")` always resolves to `process.cwd()`, which causes problems when people use the `Linter` API in ESLint where the `basePath` of a `ConfigArray` is set to an empty string. This ensures that only non-empty `basePath` strings are passed to `path.relative()`. Refs eslint/eslint#17669
@magne4000 did you try with ESLint/FlatESLint class instead of Linter? As noted in the Linter docs:
For example: import api from 'eslint/use-at-your-own-risk';
import { join } from 'node:path';
import * as tsParseForESLint from '@typescript-eslint/parser';
const { FlatESLint } = api;
const config = [
{
languageOptions: {
parser: tsParseForESLint,
},
files: ['**/*.ts', '**/*.js', '**/*.tsx', '**/*.jsx'],
},
];
const eslint = new FlatESLint({
cwd: "/tmp",
overrideConfigFile: true,
overrideConfig: config
});
const [result] = await eslint.lintText(
'const a = "";',
{
filePath: join('/tmp', 'test.ts')
}
);
console.log(result); |
@mdjermanovic yes I did, it is indeed clearer to understand what happens here.
Reading the documentation I was not detered by this particular message it seems, as documented I'm not sure how you want to progress with this issue. I think that what @nzakas discovered with |
Yes, this is still a bug we need to fix. |
After giving this some thought, I think there are actually two problems with the current implementation. First, Second, treating |
I'm working on this. |
Note from the TSC meeting: we are still trying to decide whether or not to address the second problem (treating |
@mdjermanovic It seems like we solved the most pressing part of this in #17705. I think we can close this now? |
Yes, I also think we can close this now. Starting from ESLint v8.54.0, const { Linter } = require("eslint");
const linter = new Linter({
configType: "flat",
cwd: "/tmp" // <-
});
const code = "foo";
const config = [{
files: ["**/*.ts"],
rules: {
"no-undef": "error"
}
}];
const filename = "/tmp/myfile.ts";
const report = linter.verifyAndFix(code, config, filename);
console.log(report);
/*
{
fixed: false,
messages: [
{
ruleId: 'no-undef',
severity: 2,
message: "'foo' is not defined.",
line: 1,
column: 1,
nodeType: 'Identifier',
messageId: 'undef',
endLine: 1,
endColumn: 4
}
],
output: 'foo'
}
*/ |
Environment
Node version: v16.20.0
npm version: v8.19.4
Local ESLint version: Not found
Global ESLint version: Not found
Operating System: linux 6.5.7-arch1-1
What parser are you using?
Default (Espree)
What did you do?
Configuration
What did you expect to happen?
I want to be able to override FlatConfigArray options
What actually happened?
There is no option to forward options to
FlatConfigArray
Link to Minimal Reproducible Example
https://eslint.org/play/#eyJ0ZXh0IjoiaW1wb3J0IHsgTGludGVyIH0gZnJvbSBcImVzbGludFwiO1xuaW1wb3J0ICogYXMgdHNQYXJzZUZvckVTTGludCBmcm9tIFwiQHR5cGVzY3JpcHQtZXNsaW50L3BhcnNlclwiO1xuXG5jb25zdCBjb25maWcgPSBbXG4gIHtcbiAgICBsYW5ndWFnZU9wdGlvbnM6IHtcbiAgICAgIHBhcnNlcjogdHNQYXJzZUZvckVTTGludCxcbiAgICB9LFxuICAgIGZpbGVzOiBbXCIqKi8qLnRzXCIsIFwiKiovKi5qc1wiLCBcIioqLyoudHN4XCIsIFwiKiovK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vciJdLCJuby1zcGFyc2UtYXJyYXlzIjpbImVycm9yIl0sIm5vLXRoaXMtYmVmb3JlLXN1cGVyIjpbImVycm9yIl0sIm5vLXVuZGVmIjpbImVycm9yIl0sIm5vLXVuZXhwZWN0ZWQtbXVsdGlsaW5lIjpbImVycm9yIl0sIm5vLXVucmVhY2hhYmxlIjpbImVycm9yIl0sIm5vLXVuc2FmZS1maW5hbGx5IjpbImVycm9yIl0sIm5vLXVuc2FmZS1uZWdhdGlvbiI6WyJlcnJvciJdLCJuby11bnNhZmUtb3B0aW9uYWwtY2hhaW5pbmciOlsiZXJyb3IiXSwibm8tdW51c2VkLWxhYmVscyI6WyJlcnJvciJdLCJuby11bnVzZWQtdmFycyI6WyJlcnJvciJdLCJuby11c2VsZXNzLWJhY2tyZWZlcmVuY2UiOlsiZXJyb3IiXSwibm8tdXNlbGVzcy1jYXRjaCI6WyJlcnJvciJdLCJuby11c2VsZXNzLWVzY2FwZSI6WyJlcnJvciJdLCJuby13aXRoIjpbImVycm9yIl0sInJlcXVpcmUteWllbGQiOlsiZXJyb3IiXSwidXNlLWlzbmFuIjpbImVycm9yIl0sInZhbGlkLXR5cGVvZiI6WyJlcnJvciJdfX19
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: