Skip to content
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

flowtype/sort-keys throws TypeError when handling interface types with method signatures with return types #455

Comments

@sompylasar
Copy link
Contributor

interface IFoo {
  b(): void;
  a(): void;
}
TypeError: Cannot read property 'range' of null
Occurred while linting <text>:2
    at properties.map.property (/sandbox/node_modules/eslint-plugin-flowtype/dist/rules/sortKeys.js:68:63)
    at Array.map (<anonymous>)
    at generateOrderedList (/sandbox/node_modules/eslint-plugin-flowtype/dist/rules/sortKeys.js:42:28)
    at generateFix (/sandbox/node_modules/eslint-plugin-flowtype/dist/rules/sortKeys.js:128:20)
    at Object.fix (/sandbox/node_modules/eslint-plugin-flowtype/dist/rules/sortKeys.js:181:30)
    at normalizeFixes (/sandbox/node_modules/eslint/lib/linter/report-translator.js:178:28)
    at args (/sandbox/node_modules/eslint/lib/linter/report-translator.js:347:49)
    at Object.report (/sandbox/node_modules/eslint/lib/linter/linter.js:920:41)
    at _lodash.default.forEach.identifierNode (/sandbox/node_modules/eslint-plugin-flowtype/dist/rules/sortKeys.js:173:17)
    at arrayEach (/sandbox/node_modules/lodash/lodash.js:516:11)

Minimal repro on CodeSandbox Node.js: https://codesandbox.io/s/compassionate-hooks-3zp3w?file=/src/index.js:530-590

// CodeSandbox Node.js
// dependencies: eslint, babel-eslint, eslint-plugin-flowtype
const { ESLint } = require("eslint");
const http = require("http");

http
  .createServer(function (req, res) {
    (async function main() {
      const eslint = new ESLint({
        baseConfig: {
          parser: "babel-eslint",
          plugins: ["eslint-plugin-flowtype"],
          rules: {
            "flowtype/sort-keys": "error"
          }
        },
        useEslintrc: false
      });
      const results = await eslint.lintText(`
interface IFoo {
  b(): void;
  a(): void;
}
`);
      const formatter = await eslint.loadFormatter("compact");
      const resultText = formatter.format(results);
      res.write("Lint Success: " + resultText);
      res.end();
    })().catch((error) => {
      res.write("Lint Error: " + (error.stack || String(error)));
      res.end();
    });
  })
  .listen(8080);
@gajus gajus added the bug label Nov 7, 2020
gajus pushed a commit that referenced this issue Feb 18, 2021
* fix: annotate fixable rules

...and fix a few lint errors

The latest version of ESLint RuleTester has a hard requirement that all fixable rules declare `meta.fixable`.
I was going to work on an issue, but this was blocking all tests after doing a fresh npm install.

* fix: [sort-keys] handle method signatures

Fixes #455
@gajus
Copy link
Owner

gajus commented Feb 18, 2021

🎉 This issue has been resolved in version 5.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Feb 18, 2021
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment