sublime text3 jshint error "Incompatible values for 'undefined' and 'undefined' linting options." when using IIFE expression - sublimetext3

OS: macOS Sierra 10.12.5 .
Sublime Text: Build 3126 .
jshint v2.9.5 .
eslint v4.4.0 .
I have installed below packages for linting the js file
sublimeLinter-contrib-eslint
sublimeLinter-jshint
In my each .js file, IIFE (function(){ has been written on the top of the file BUT linter gives below error in gutter
Incompatible values for "undefined" and "undefined" linting options.
I have both .jshintrc and .eslintrc file in my project root directory BUT I am a bit confused
1. Which linter throw this error? and
2. How to resolve/fix it?
-.jshintrc_
{
"node": true,
"esversion": 6,
"globals" : {
"moment": true,
"saveAs": true
}
}
.eslintrc
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"globals": {
"angular": true,
"module": true,
"inject": true,
"moment": true,
"saveAs": true,
"AWS": true,
"require": false
},
"rules": {
"indent": [0,"tab"],
"linebreak-style": [0, "unix"],
"semi": [2, "always"]
}
}
JS file
(function() {
'use strict';
angular.module().controller(function () { //....code.... });
})();
I have tried the rules as per eslint documentation
"rules": {
"wrap-iife": [2, "outside"]
}
tried all possible values but did not succeed.

Found solution by using Debug mode for sublimeLinter.
there are mixing of 2 .jshintrc files. one is the default ( which can be viewed by (context menu > JSHint > Set Linting Preferences ) and other is custom .jshintrc which located in my project root directory and also there are 2 property esnext and esversion written which I think is not valid. from this refrence
so first clear all comments from default .jshintrc (/Users//Library/Application Support/Sublime Text 3/Packages/JSHint Gutter/.jshintrc) and remove esversion property from custom .jshintrc file and everything is working fine now.

Related

How to use import-map with Deno

I have this import_map.json file:
{
"imports": {
"node_modules/" : "./node_modules"
}
}
at a high-level I am trying to create some compatibility for .ts files, for both Deno and Node.
My imports look like this:
import * as util from 'util';
import chalk from "node_modules/chalk";
When I run this:
deno run --import-map='import_map.json' ./src/linked-queue.ts
I get this loathsome error:
Import map diagnostics:
- Invalid target address "file:///.../linked-queue/node_modules" for package specifier "node_modules/". Package address targets must end with "/".
error: Blocked by null entry for ""node_modules/""
at file:///.../linked-queue/src/linked-queue.ts:4:19
Anyone know how to resolve this error?
"imports": {
"node_modules/" : "./node_modules/"
}
Add a trailing slash on the target specifier. See also the spec and the source.
The manual covers this scenario in the following three sections:
4.1 - Using npm packages with npm specifiers
4.3 - The std/node Library
4.4 - Using Import Maps
I'll show a reproducible example rather than copy + paste everything from the docs (because a few copied snippets aren't really enough; this is a multi-faceted issue) — however take note of the values in the import map, as they are derived by reading through all three linked sections of the documentation:
./import_map.json:
{
"imports": {
"chalk": "npm:chalk#5.2.0",
"node:util": "https://deno.land/std#0.170.0/node/util.ts"
}
}
./deno.jsonc:
{
"importMap": "./import_map.json",
"tasks": {
// I included these permissions (which are required by chalk) in advance to avoid needing to grant them one-by-one at runtime:
"dev": "deno run --allow-env=FORCE_COLOR,TF_BUILD,TERM,CI,TEAMCITY_VERSION,COLORTERM,TERM_PROGRAM,TERM_PROGRAM_VERSION src/linked-queue.ts"
}
}
./src/linked-queue.ts:
import * as util from "node:util";
import chalk from "chalk";
console.log('util:', typeof util); // util: object
console.log('chalk:', typeof chalk); // chalk: function
Running in the terminal using the defined task:
% deno --version
deno 1.29.1 (release, x86_64-apple-darwin)
v8 10.9.194.5
typescript 4.9.4
% deno task dev
Task dev deno run --allow-env=FORCE_COLOR,TF_BUILD,TERM,CI,TEAMCITY_VERSION,COLORTERM,TERM_PROGRAM,TERM_PROGRAM_VERSION src/linked-queue.ts
util: object
chalk: function
% echo $?
0
So far, everything is great in Deno.
Let's check to see that the same code works without modification in Node.js. The following files need to be added to compile and run using Node, since it doesn't include all of Deno's built-in tooling:
./package.json:
{
"name": "so-74905332",
"version": "0.1.0",
"type": "module",
"scripts": {
"compile": "tsc",
"dev": "tsc && node src/linked-queue.js"
},
"license": "MIT",
"dependencies": {
"chalk": "5.2.0"
},
"devDependencies": {
"#types/node": "^18.11.17",
"typescript": "^4.9.4"
}
}
./tsconfig.json:
Why these values? I'm just using a recommended base, linked to from the TS repo wiki:
// This file was autogenerated by a script
// Equivalent to a config of: strictest extends esm extends node18
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node LTS + ESM + Strictest",
"_version": "18.12.1",
"compilerOptions": {
"lib": [
"es2022"
],
"module": "es2022",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"exactOptionalPropertyTypes": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"importsNotUsedAsValues": "error",
"checkJs": true
}
}
Running in the terminal using the defined npm script:
% node --version
v18.12.1
% npm install
added 3 packages, and audited 4 packages in 1s
1 package is looking for funding
run `npm fund` for details
found 0 vulnerabilities
% npm run dev
> so-74905332#0.1.0 dev
> tsc && node src/linked-queue.js
util: object
chalk: function
% echo $?
0
The same module source code also works in Node.js.

Jest Typescript with ES Module in node_modules error - Must use import to load ES Module:

I'm trying to write a simple jest test for a 3rd party package were using that only exports an ES module. It's a wrapper around an http server.
Here is a test repo I setup (just run yarn && yarn jest to reproduce): https://github.com/jamesopti/hocuspocus-testing
No matter what config I experiment with, I still get this error when trying to run it:
Must use import to load ES Module: /Users/j/hocuspocus-testing/node_modules/#hocuspocus/server/dist/hocuspocus-server.esm.js
> 1 | import { Server, Hocuspocus } from '#hocuspocus/server'
| ^
2 | import * as request from 'supertest'
3 |
4 | describe('Server (e2e)', () => {
Things I've tried already:
The Jest instructions on ES modules: https://jestjs.io/docs/ecmascript-modules
In Jest configuration using transformIgnorePatterns
transformIgnorePatterns: ['node_modules/(?!#hocuspocus/)']
Using Babel via babel-jest
modifying transform setup in Jest configuration as '^.+\.jsx?$': 'babel-jest', '^.+\.tsx?$': 'ts-jest'
Ran into the error You appear to be using a native ECMAScript module configuration file, which is only supported when running Babel asynchronously.
Using .babel.config.js instead of .babelrc.js
Any ideas what I'm missing here? I thought this would be straightforward
[EDIT 1] - Added tsconfig.json and a working src/index.ts file to the example repo.
So for anyone still hitting this, ESM configuration explained in this section of documentation :
https://kulshekhar.github.io/ts-jest/docs/guides/esm-support
{
// [...]
"jest": {
"extensionsToTreatAsEsm": [".ts"],
"globals": {
"ts-jest": {
"useESM": true
}
}
}
}
JAN 2023: ES2022, TypeScript 4.9.4, jest 29.3.1, ts-jest 29.0.3
This is what worked for me, after 2 hours of frustration.
I used this configuration in jest.config.ts:
import type { JestConfigWithTsJest } from 'ts-jest'
const config: JestConfigWithTsJest = {
extensionsToTreatAsEsm: ['.ts'],
verbose: true,
preset: 'ts-jest/presets/default-esm',
testEnvironment: 'node',
transform: {
'^.+\\.(ts|tsx)?$': ['ts-jest', { useESM: true }]
},
testPathIgnorePatterns: ['./dist']
}
export default config
Change the test script in package.json to:
I use pnpm. Change to npx jest with npm,
or yarn exec with yarn
...
"scripts": {
...
"test": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest",
...
}
...
tsconfig.json:
{
"compilerOptions": {
"rootDirs": ["src"],
"outDir": "dist",
"lib": ["ES2022"],
"target": "ES2022",
"module": "ES2022",
"composite": true,
"moduleResolution": "node",
"declaration": true,
"declarationMap": true,
"incremental": true,
"esModuleInterop": true,
"types": ["jest", "node", "#types/jest"],
"sourceMap": true
},
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
},
"include": ["./src/**/*", "./tests/**/*"]
}
See this (rather confusing) documentation for reference:
https://kulshekhar.github.io/ts-jest/docs/guides/esm-support/
You don't have a tsconfig.json file that specifies module. Therefore it uses the default, where it transpiles all your modules to CommonJS syntax, which uses require.
If you actually look at your dist/hocuspocus-server.esm.js, you should see it using require over the ESM import syntax.
I was having the same problem with my svelte app and testing. I ultimately traced it to having a jest.config.js and a jest.config.json in my root folder. It seems that jest does not have automatic config file resolution and was using a default configuration instead of either of my specified configurations.

Trying to disable no-template-curly-in-string ESlint rule on my project

Getting this error
./src/locale/translations.js
Line 4:5: Unexpected template string expression no-template-curly-in-string
Line 6:13: Unexpected template string expression no-template-curly-in-string
And trying to disable for the whole project:
// .eslintrc
{
"rules": {
"no-template-curly-in-string": "off",
"template-curly-in-string": "off"
// "no-template-curly-in-string": 0,
// "template-curly-in-string": 0
// "no-template-curly-in-string": false,
// "template-curly-in-string": false
}
}
None of those work.
Try to update to react-scripts#4.0.0 because I found an issue in the previous version 3.X.X where the eslint was ignored.
Update:
npm install --save --save-exact react-scripts#4.0.0
or
yarn add --exact react-scripts#4.0.0
This works in my case ;)
I was able to disable it with the following:
// package.json
"eslintConfig": {
"extends": "react-app",
"rules": {
"no-template-curly-in-string": "off"
}
The trick was to add EXTEND_ESLINT=true to my environment file after updating package.json, and then restarting my server.

Why is linting failing with "Unexpected token ." on "import.meta.url"?

I have the following lint config...
{
"extends": ["eslint:recommended", "google"],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"require-jsdoc": 1
},
"env": {
"es6": true
}
}
and the following code...
const __dirname = path.dirname(new URL(import.meta.url).pathname);
//^Error is...
But when it lints I get...
9:46 error Parsing error: Unexpected token .
This is a pretty common piece of code so I am confused.
Update
solved with...
"ignorePatterns": ["unclean.mjs", "node_modules"],
But I would like a solution where I don't have to ignore an entire file.
It is a syntax error because the default parser of ESLint only supports stage 4 proposals, but import.meta is currently stage 3. For now, you must change the parser to "babel-eslint" or "#typescript-eslint/parser" in order to parse import.meta.
That phrase is a syntax error because import is a keyword in EcmaScript. Therefore import.meta is as invalid as if.foo or switch.foo.

need a correct eslintrc for async/await - using 7.6+ nodejs

With the latest version of nodejs 7.6+ I started using async/await.
I was using jshint but from what I read they currently do support this syntax and some suggested using eslint.
So ok I set eslint up but argh.. it flags async functions too.
Parsing error: Unexpected token init (Fatal)
I know there is nothing wrong as my code is running fine it's just the linter. Too if I comment out an async function it just flags the next one. IN fact eslint only flags the first async found with this error not all of them (what up with that?)
Here is the eslintrc file made using the init wizard. I was hoping just asking for node and es6 for env would be sufficient...apparently not.
module.exports = {
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
}
};
What is the fix?
I've tried several versions of .eslintrc and even saw there are a few issues related at the eslint repo but none are helping me to resolve this. I don't think it's a bug just missing something about getting eslint set up correctly for native nodejs using commonjs (no babel).
Who knows maybe babel plugin is required to make this work even though I am not using babel??? If that's true how do I set that up.
Since async/await is an ES2017 feature, you need to add that to your .eslintrc.js:
module.exports = {
// ...
"parserOptions": {
"ecmaVersion": 2017
},
// ...
}

Resources