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

The value variable for each must either be a valid identifier (e.g. item) or a pair of identifiers in square brackets (e.g. [key, value]). #10

Closed
zhou-ins opened this issue Jun 3, 2021 · 2 comments

Comments

@zhou-ins
Copy link

zhou-ins commented Jun 3, 2021

I installed eslint-plugin-pug in the pug project, and when I executed eslint to detect the file, it reported this error:

The value variable for each must either be a valid identifier (e.g. item) or a pair of identifiers in square brackets (e.g. [key, value]).

The specific error is as follows:

Error: Pug:127:34
  125|           if offers.length > 0
  126|             .house-offer-list
> 127|               each item in offers
------------------------------------------^
  128|                 if item.agent
  129|                   .house-offer-list-item
  130|                     a.house-offer-main.flex-row.flex-vertical-middle(href='/agents/' + item.agentId)&attributes({ 'data-log': 2013 })
The value variable for each must either be a valid identifier (e.g. `item`) or a pair of identifiers in square brackets (e.g. `[key, value]`).
  at makeError (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-error/index.js:34:13)
  at Lexer.error (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:62:15)
@zhou-ins
Copy link
Author

zhou-ins commented Jun 3, 2021

I installed eslint-plugin-pug in the pug project, and when I executed eslint to detect the file, it reported this error:

The value variable for each must either be a valid identifier (e.g. item) or a pair of identifiers in square brackets (e.g. [key, value]).

The specific error is as follows:

Error: Pug:127:34
125| if offers.length > 0
126| .house-offer-list

127| each item in offers
------------------------------------------^
128| if item.agent
129| .house-offer-list-item
130| a.house-offer-main.flex-row.flex-vertical-middle(href='/agents/' + item.agentId)&attributes({ 'data-log': 2013 })
The value variable for each must either be a valid identifier (e.g. item) or a pair of identifiers in square brackets (e.g. [key, value]).
at makeError (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-error/index.js:34:13)
at Lexer.error (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:62:15)
at Lexer.eachOf (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:1108:14)
at Lexer.callLexerFunction (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:1647:23)
at Lexer.advance (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:1676:12)
at Lexer.callLexerFunction (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:1647:23)
at Lexer.getTokens (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:1706:12)
at lex (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/node_modules/pug-lexer/index.js:12:42)
at Object.exports.parsePug (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/utils.js:48:20)
at exports.preprocess (/Users/FangGeek/company_projects/client-web-mobile/node_modules/eslint-plugin-pug/utils.js:71:23)
husky > pre-commit hook failed (add --no-verify to bypass)
zhouliying:client-web-mobile FangGeek$ npm install
npm WARN [email protected] requires a peer of acorn@^6.0.0 || ^7.0.0 || ^8.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of eslint@^4.19.1 || ^5.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of pug@^2.0.0 but none is installed. You must install peer dependencies yourself.

How can i solve it

@valpackett
Copy link
Owner

As this is an error from pug-lexer, this means the syntax cannot be parsed. That's not an error in my plugin, that's a syntax error in your file. Indeed, trying to load a similar file with pug itself fails in the same way:

> const pug = require('pug')
> pug.compileFile('test/fixtures/wat.pug')
Uncaught Error: test/fixtures/wat.pug:2:22
    1| .house-offer-list
  > 2|   each item in offers
----------------------------^
    3|     if item.agent
    4|       .house-offer-list-item
    5|

The value variable for each must either be a valid identifier (e.g. `item`) or a pair of identifiers in square brackets (e.g. `[key, value]`).

What it doesn't like is the offers identifier, and it seems like… because it begins with of. For now just rename the variable :)

Reported to pug-lexer: pugjs/pug-lexer#85

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