valpackett/eslint-plugin-pug

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]`).

zhou-ins opened this issue · 2 comments

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)

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 acorn-jsx@5.3.1 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 eslint-config-airbnb-base@13.1.0 requires a peer of eslint@^4.19.1 || ^5.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN pug-loader@2.4.0 requires a peer of pug@^2.0.0 but none is installed. You must install peer dependencies yourself.

How can i solve it

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