frjo / hugo-theme-zen

A fast and clean Hugo base theme with css-grid and Hugo pipes support.
https://zen-demo.xdeb.org/
GNU General Public License v2.0
276 stars 80 forks source link

eslint giving errors with tip of 'main' #82

Closed danielfdickinson closed 1 year ago

danielfdickinson commented 1 year ago

On Windows 10:

PS C:\Users\DanielDickinson\Build\hugo-dfd-sites\dfd-hugo-theme-zen> npm run lint-theme:js

> zen@1.0.0 lint-theme:js
> eslint "assets/js/**/*.js"

C:\Users\DanielDickinson\Build\hugo-dfd-sites\dfd-hugo-theme-zen\assets\js\search.js
  8:1  error  Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

C:\Users\DanielDickinson\Build\hugo-dfd-sites\dfd-hugo-theme-zen\assets\js\tracking.js
  8:1  error  Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

✖ 2 problems (2 errors, 0 warnings)

With node 16.19.1.

The line in question (in both cases) is:

import * as params from '@params';
frjo commented 1 year ago

Yes, eslint does not like import statement in a script (none module). This import is however for ESBuild built in to Hugo and will not be part of the output.

Tried to find way to remove the error but decided to just ignore it. Most likely only us two who care about linting in the Zen theme :-).

danielfdickinson commented 1 year ago

I found way to quiet eslint on this:

parserOptions:
  ecmaVersion: 12
  sourceType: module

combined with

rules:
  strict: 0

in .eslintrc.yaml. Of course this has side effects that might be a problem (like not warning of misuse of strict), so you'll have to contemplate what you think of that.

laygond commented 1 year ago

Do not complicate yourself.

I got rid of the error by just deleting import * as params from '@params'; The only reason this is needed is to set params.searchLimit

So delete params.searchLimit and replace it with its default value of 20 and your code will finally run.

danielfdickinson commented 1 year ago

@laygond Doing that removes the ability to set searchLimit in the site config file (e.g. config.yaml or config.toml).

frjo commented 1 year ago

Added comments to disable linting for the import lines so closing this.