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

sourceCode undefined in every rule #45

Closed
Silon opened this issue Nov 5, 2023 · 2 comments
Closed

sourceCode undefined in every rule #45

Silon opened this issue Nov 5, 2023 · 2 comments

Comments

@Silon
Copy link

Silon commented Nov 5, 2023

I created package with own rules where I use stylistic with next/recommended

// eslin-plugin-test/index.js

module.exports = {
  configs: {
    nextjs: {
      plugins: ["@stylistic"],
      extends: ["plugin:@next/next/recommended"],
      rules: {
        "@stylistic/max-len": ["error", 120],
      },
    },
  },
};

Then I use it in my NextJS project

//  nextproject/.eslintrc.js

/** @type {import('eslint').Linter.Config} */
module.exports = {
  root: true,
  extends: ['plugin:@test/test/nextjs'],
  parserOptions: {
    project: './tsconfig.json',
    ecmaVersion: 'latest',
  },
  env: {
    es6: true,
    node: true,
  },
};

The problem is that every rule added into rules in index.js file causes an error:

[Error - 18:41:35] TypeError: Cannot read properties of undefined (reading 'lines')
Occurred while linting /Users/silon/Developer/nextjs-template/.eslintrc.js:2
Rule: "@stylistic/max-len"
    at checkProgramForMaxLength

The problem in this case is in max-len.js file in this line:

function checkProgramForMaxLength(node) {
  // split (honors line-ending)
  const lines = sourceCode.lines;

When I remove max-len rule from index.js eslint works good

@ota-meshi
Copy link
Member

Hi @Silon.
I think you need to use ESLint v8.40 or newer.
New those properties were added in v8.40.

https://eslint.org/blog/2023/05/eslint-v8.40.0-released

@Silon
Copy link
Author

Silon commented Nov 6, 2023

@ota-meshi you're right! In my library I got newest but project had old version. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants