orzechowskid / flymake-eslint

Flymake backend for Javascript using eslint
MIT License
43 stars 11 forks source link

Is it possible to run it from project's root? #19

Closed marc0s closed 4 years ago

marc0s commented 4 years ago

My eslint configuration file has the parserOptions.project property defined to ./tsconfig.json.

This breaks when flymake-eslint runs eslint because, if I'm not mistaken, it does so from the directory containing the file the buffer is visiting as there's no ./tsconfig.json there (but some directories up).

Error reported when running flymake-eslint-enable is


/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts
  0:0  error  Parsing error: File '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/tsconfig.json' not found

✖ 1 problem (1 error, 0 warnings)```

Any hint on how to workaround it or fixing guidelines will be appreciated.

Thanks!
orzechowskid commented 4 years ago

hi! could you provide your entire .eslintrc.js file so I can attempt to reproduce your issue? I set parserOptions.project to "./jsconfig.json" in the configuration for a project I have, and flymake-eslint behaved as expected (though maybe my parser ignores that option?).

what happens if you run cd /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar && eslint --verbose ./miau.ts ? do you see anything suspicious in the debug output?

thanks!

marc0s commented 4 years ago

I forgot to come back on this, as it now seems to be working (spent some time in the afternoon playing with this and really don't recall what did the trick), but now I ran the command you give me and it might indicate (correct me if I'm wrong) a problem with eslint itself (or maybe the typescript parser, as I'd say it's what will access tsconfig.json):

❯ cd

~
❯ cd /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar && eslint --debug ./miau.ts
  eslint:cli CLI args: [ '--debug', './miau.ts' ] +0ms
  eslint:cli Running on files +4ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', patterns: [ '/node_modules/*', '/bower_components/*' ] } +2ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', loose: false } ] +0ms
  eslint:ignore-pattern   processed: { basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', patterns: [ '/node_modules/*', '/bower_components/*' ] } +0ms
  eslint:file-enumerator Start to iterate files: [ './miau.ts' ] +0ms
  eslint:file-enumerator File: /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts +0ms
  eslint:cascading-config-array-factory Load config files for /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar. +0ms
  eslint:cascading-config-array-factory No cache found: /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar. +0ms
  eslint:config-array-factory Config file not found on /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar +0ms
  eslint:cascading-config-array-factory No cache found: /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo. +0ms
  eslint:config-array-factory Config file not found on /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo +0ms
  eslint:cascading-config-array-factory No cache found: /home/marcos/Projects/Sandbox/flymake-eslint-error/test. +0ms
  eslint:config-array-factory Config file not found on /home/marcos/Projects/Sandbox/flymake-eslint-error/test +1ms
  eslint:cascading-config-array-factory No cache found: /home/marcos/Projects/Sandbox/flymake-eslint-error. +1ms
  eslint:config-array-factory Loading JS config file: /home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js +0ms
  eslint:config-array-factory Config file found: /home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js +1ms
  eslint:config-array-factory Loading {extends:"plugin:@typescript-eslint/recommended"} relative to /home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js +0ms
  eslint:config-array-factory Loading plugin "@typescript-eslint" from /home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js +0ms
  eslint:config-array-factory Loaded: @typescript-eslint/eslint-plugin@2.9.0 (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +2ms
  eslint:config-array-factory Plugin /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 215ms +215ms
  eslint:config-array-factory Loading {extends:"./configs/base.json"} relative to /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +1ms
  eslint:config-array-factory package.json was not found: Cannot find module './configs/base.json/package.json'
Require stack:
- /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js +0ms
  eslint:config-array-factory Loaded: ./configs/base.json (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.json) +0ms
  eslint:config-array-factory Loading JSON config file: /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.json +0ms
  eslint:config-array-factory Loading parser "@typescript-eslint/parser" from /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.json +1ms
  eslint:config-array-factory Loaded: @typescript-eslint/parser@2.9.0 (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/parser/dist/parser.js) +1ms
  eslint:config-array-factory Loading plugin "@typescript-eslint" from /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.json +32ms
  eslint:config-array-factory Loaded: @typescript-eslint/eslint-plugin@2.9.0 (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +0ms
  eslint:config-array-factory Plugin /home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js loaded in: 0ms +0ms
  eslint:config-array-factory Loading parser "@typescript-eslint/parser" from /home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js +1ms
  eslint:config-array-factory Loaded: @typescript-eslint/parser@2.9.0 (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/parser/dist/parser.js) +0ms
  eslint:cascading-config-array-factory No cache found: /home/marcos/Projects/Sandbox. +254ms
  eslint:config-array-factory Config file not found on /home/marcos/Projects/Sandbox +0ms
  eslint:cascading-config-array-factory No cache found: /home/marcos/Projects. +0ms
  eslint:config-array-factory Config file not found on /home/marcos/Projects +0ms
  eslint:cascading-config-array-factory No cache found: /home/marcos. +0ms
  eslint:cascading-config-array-factory Stop traversing because of considered root. +0ms
  eslint:rules Loading rule 'camelcase' (remaining=274) +0ms
  eslint:rules Loading rule 'no-array-constructor' (remaining=273) +10ms
  eslint:rules Loading rule 'no-empty-function' (remaining=272) +0ms
  eslint:rules Loading rule 'no-unused-vars' (remaining=271) +7ms
  eslint:rules Loading rule 'no-use-before-define' (remaining=270) +2ms
  eslint:rules Loading rule 'no-var' (remaining=269) +4ms
  eslint:rules Loading rule 'prefer-const' (remaining=268) +1ms
  eslint:rules Loading rule 'prefer-rest-params' (remaining=267) +1ms
  eslint:rules Loading rule 'prefer-spread' (remaining=266) +0ms
  eslint:cascading-config-array-factory Configuration was determined: ConfigArray [ { name: 'DefaultIgnorePattern', filePath: '', criteria: null, env: undefined, globals: undefined, ignorePattern: IgnorePattern { patterns: [Array], basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', loose: false }, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { name: '../../../.eslintrc.js » plugin:@typescript-eslint/recommended » ./configs/base.json', filePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.json', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/parser/dist/parser.js', id: '@typescript-eslint/parser', importerName: '../../../.eslintrc.js » plugin:@typescript-eslint/recommended » ./configs/base.json', importerPath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/configs/base.json' }, parserOptions: { sourceType: 'module' }, plugins: { '@typescript-eslint': [Object] }, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: undefined, settings: undefined }, { name: '../../../.eslintrc.js » plugin:@typescript-eslint/recommended', filePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/eslint-plugin/dist/index.js', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: undefined, parserOptions: undefined, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: { '@typescript-eslint/adjacent-overload-signatures': 'error', '@typescript-eslint/ban-ts-ignore': 'error', '@typescript-eslint/ban-types': 'error', camelcase: 'off', '@typescript-eslint/camelcase': 'error', '@typescript-eslint/class-name-casing': 'error', '@typescript-eslint/consistent-type-assertions': 'error', '@typescript-eslint/explicit-function-return-type': 'warn', '@typescript-eslint/interface-name-prefix': 'error', '@typescript-eslint/member-delimiter-style': 'error', 'no-array-constructor': 'off', '@typescript-eslint/no-array-constructor': 'error', 'no-empty-function': 'off', '@typescript-eslint/no-empty-function': 'error', '@typescript-eslint/no-empty-interface': 'error', '@typescript-eslint/no-explicit-any': 'warn', '@typescript-eslint/no-inferrable-types': 'error', '@typescript-eslint/no-misused-new': 'error', '@typescript-eslint/no-namespace': 'error', '@typescript-eslint/no-non-null-assertion': 'warn', '@typescript-eslint/no-this-alias': 'error', 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': 'warn', 'no-use-before-define': 'off', '@typescript-eslint/no-use-before-define': 'error', '@typescript-eslint/no-var-requires': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', '@typescript-eslint/triple-slash-reference': 'error', '@typescript-eslint/type-annotation-spacing': 'error', 'no-var': 'error', 'prefer-const': 'error', 'prefer-rest-params': 'error', 'prefer-spread': 'error' }, settings: undefined }, { name: '../../../.eslintrc.js', filePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js', criteria: null, env: undefined, globals: undefined, ignorePattern: undefined, noInlineConfig: undefined, parser: { error: null, filePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/parser/dist/parser.js', id: '@typescript-eslint/parser', importerName: '../../../.eslintrc.js', importerPath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/.eslintrc.js' }, parserOptions: { ecmaVersion: 2018, sourceType: 'module', project: './tsconfig.json' }, plugins: undefined, processor: undefined, reportUnusedDisableDirectives: undefined, root: undefined, rules: {}, settings: undefined } ] on /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar +30ms
  eslint:ignore-pattern Create with: [ IgnorePattern { patterns: [ '/node_modules/*', '/bower_components/*' ], basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', loose: false } ] +288ms
  eslint:ignore-pattern   processed: { basePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar', patterns: [ '/node_modules/*', '/bower_components/*' ] } +0ms
  eslint:ignore-pattern Check { filePath: '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts',
  dot: false,
  relativePath: 'miau.ts',
  result: false } +1ms
  eslint:cli-engine Lint /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts +0ms
  eslint:linter Linting code for /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts (pass 1) +0ms
  eslint:linter Verify +0ms
  eslint:linter With ConfigArray: /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts +0ms
  eslint:linter Parsing error: File '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/tsconfig.json' not found.
  eslint:linter Error: File '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/tsconfig.json' not found.
    at Object.diagnosticReporter [as onUnRecoverableConfigFileDiagnostic] (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/typescript-estree/dist/create-program/createWatchProgram.js:81:11)
    at Object.getParsedCommandLineOfConfigFile (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/typescript/lib/typescript.js:26344:18)
    at parseConfigFile (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/typescript/lib/typescript.js:100544:43)
    at Object.createWatchProgram (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/typescript/lib/typescript.js:100219:13)
    at createWatchProgram (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/typescript-estree/dist/create-program/createWatchProgram.js:235:15)
    at Object.getProgramsForProjects (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/typescript-estree/dist/create-program/createWatchProgram.js:162:30)
    at Object.createProjectProgram (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/typescript-estree/dist/create-program/createProjectProgram.js:18:74)
    at getProgramAndAST (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:60:32)
    at Object.parseAndGenerateServices (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/typescript-estree/dist/parser.js:294:30)
    at Object.parseForESLint (/home/marcos/Projects/Sandbox/flymake-eslint-error/node_modules/@typescript-eslint/parser/dist/parser.js:53:51) +21ms
  eslint:linter Generating fixed text for /home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts (pass 1) +0ms
  eslint:source-code-fixer Applying fixes +0ms
  eslint:source-code-fixer shouldFix parameter was false, not attempting fixes +0ms
  eslint:file-enumerator Complete iterating files: ["./miau.ts"] +310ms
  eslint:cli-engine Linting complete in: 311ms +23ms

/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts
  0:0  error  Parsing error: File '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/tsconfig.json' not found

✖ 1 problem (1 error, 0 warnings)

~/Projects/Sandbox/flymake-eslint-error/test/foo/bar
❯ cat ../../../.eslintrc.js
module.exports =  {
    parser:  '@typescript-eslint/parser',  // Specifies the ESLint parser
    extends:  [
        'plugin:@typescript-eslint/recommended',  // Uses the recommended rules from the @typescript-eslint/eslint-plugin
    ],
    parserOptions:  {
        ecmaVersion:  2018,  // Allows for the parsing of modern ECMAScript features
        sourceType:  'module',  // Allows for the use of imports
        project: './tsconfig.json'
    },
    rules:  {
        // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
        // e.g. "@typescript-eslint/explicit-function-return-type": "off",
    },
};

Thanks for having a look at this!

orzechowskid commented 4 years ago

aha, setting my parser to @typescript-eslint/parser does allow me to reproduce what you are seeing. thanks.

for now, you can set the value of default-directory (a buffer-local variable) to control the value of $PWD for your linter process. this can be done interactively with M-x cd or programmatically in your mode hook with (setq-local default-directory "/path/to/project/").

but because I don't know what side-effects arise from changing that variable, I should really be exposing a flymake-eslint-project-root variable and using that as $PWD when invoking the linter. give me a day or two and I should have something.

orzechowskid commented 4 years ago

released as https://github.com/orzechowskid/flymake-eslint/releases/tag/1.5.0 , and should be on MELPA in a little bit.

add this to your javascript mode-hook function to automatically set flymake-eslint-project-root to the directory containing the closest .eslintrc.js file:

  (flymake-eslint-enable)
  (setq-local flymake-eslint-project-root (locate-dominating-file buffer-file-name ".eslintrc.js"))