For using ES6 in the environment, I have to specify the .eslintrc file as:
"env": {
"node": false,
"browser": true,
"amd": true,
"mocha": true,
"jasmine": false,
"es6": true
}
But what when I want to use ES7, can I just:
"env": {
"node": false,
"browser": true,
"amd": true,
"mocha": true,
"jasmine": false,
"es7": true
}
?
For information, I looked at https://eslint.org/docs/user-guide/configuring but did not get the answer.
Update
My current file eslint file looks as following:
{
"globals": {
"com": true,
"oData": false,
"sakp": false,
"fin": true,
"cloud": true,
"bsuite": false,
"cordova": false,
"ui": true,
"webide": false,
"asyncTest": false,
"i2d": true,
"gltrade": false,
"drilldown": true,
"opaTest": false,
"ux": true,
"test": false,
"$": false,
"module": false,
"ai": false,
"notEqual": false,
"notDeepEqual": false,
"throws": false,
"ssuite": false,
"deepEqual": false,
"s2p": false,
"Promise": false,
"ehs": false,
"sinon": false,
"stop": false,
"util": true,
"slo": false,
"mdm": false,
"mytravelandexpense": false,
"strictEqual": false,
"cec": false,
"cus": false,
"notStrictEqual": false,
"fscm": false,
"fm": true,
"nw": true,
"shcm": false,
"fcg": true,
"URI": false,
"fs": true,
"retail": false,
"d3": false,
"hcm": false,
"oil": true,
"assert": false,
"hpa": false,
"ok": false,
"sap": true,
"QUnit": false,
"cross": true,
"srm": false,
"equal": false,
"expect": false,
"jQuery": false,
"publicservices": true,
"uxcc": false,
"equals": false,
"tl": false,
"travel": true
},
"env": {
"node": false,
"browser": true,
"amd": true,
"mocha": true,
"jasmine": false,
"es6": true
}
}
Where to specify es7?
To control which edition of syntax is allowed, you'll want to set the ecmaVersion under parserOptions:
{
"env": {
"node": false,
"browser": true,
"amd": true,
"mocha": true,
"jasmine": false,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2016
}
}
The value can either be the year or edition number of the specification (e.g. ECMAScript 2018 and the 9th edition have the same effect).
Related
I'm trying to turn off minification during the production build process. This is where I'm currently at in my webpack.mix.js file. However, nothing I've tried is working so far. What is the best way to do this?
webpack.mix.js
let mix = require('laravel-mix');
mix
.options({
minimize:false,
uglify: {
uglifyOptions: {
warnings: false,
comments: false,
beautify: true,
minify: false,
minimize: false,
compress: {
drop_console: true,
minimize: false,
}
}
},
cssnano:false,
})
.js('src/js/app.js', 'assets/js/common.js')
.sass('src/scss/style.scss', '').options({processCssUrls: false});
if (mix.inProduction()) {
mix.options({
minimize: false,
uglify: {
uglifyOptions: {
warnings: false,
comments: false,
beautify: false,
minify: false,
minimize: false,
compress: {
drop_console: true,
minimize: false,
}
}
},
cssnano:false,
});
}
Getting this issue when trying to run tests on my Angular microfrontend to use inside Module Federation. Angular 12, Webpack 5.
Uncaught Error: Shared module is not available for eager consumption: 5487
How to configure eager consumption for these modules?
In most cases, solve this issue by setting eager: true on your shared common Angular modules:
shared: share({
"#angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto', eager: true },
"#angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto', eager: true },
"#angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto', eager: true },
"#angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto', eager: true },
Create a separate webpack.conf for testing
You can set all shared modules to eager: true in your primary webpack.config.js, but that would force you to use a larger bundle size, one of the things Module Federation aims to avoid.
A better option could be to set up a separate webpack.test.config.js, which will just be used for running tests, and in that file set your modules to eager: true:
webpack.test.config.js
shared: share({
"#angular/core": {
eager: true,
singleton: true,
strictVersion: true,
requiredVersion: 'auto'
},
"#angular/common": {
eager: true,
singleton: true,
strictVersion: true,
requiredVersion: 'auto'
},
"#angular/common/http": {
eager: true,
singleton: true,
strictVersion: true,
requiredVersion: 'auto'
}
})
I have a React App built with parcel.js. I've added Jest and I'm attempting to run a basic test, but it looks like the code is not being transformed before hitting the test Jest encountered an unexpected token.
I'm not sure if the Parcel.js part is a red herring, but it's the thing that's a little different from the examples out there.
package.json
{
"name": "cool-tool",
"version": "1.0.0",
"description": "cool tool",
"main": "public/main.js",
"directories": {
"test": "tests"
},
"dependencies": {
"react": "^16.4.1",
"react-dom": "^16.4.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-jest": "^23.4.2",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"jest": "^23.4.2",
"parcel-bundler": "^1.9.7",
"react-test-renderer": "^16.4.2"
},
"scripts": {
"test": "jest --debug",
"start": "parcel watch assets/js/troubleshooting.js --out-dir public/js",
"build": "parcel build assets/js/troubleshooting.js --out-dir public/js"
},
"jest": {
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": "shhhh.git"
},
"author": "me",
"license": "ISC"
}
the babel.rc
{
"presets": ["env", "react"]
}
Jest run with the --debug option
{
"configs": [
{
"automock": false,
"browser": false,
"cache": true,
"cacheDirectory": "/var/folders/v4/0kv69mcn5530g0gshbwwqfgr0000gn/T/jest_dx",
"clearMocks": false,
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"filter": null,
"forceCoverageMatch": [],
"globals": {},
"haste": {
"providesModuleNodeModules": []
},
"moduleDirectories": [
"node_modules"
],
"moduleFileExtensions": [
"js",
"json",
"jsx",
"node"
],
"moduleNameMapper": {},
"modulePathIgnorePatterns": [],
"name": "6f41d9651941a1101334b070800aeec1",
"prettierPath": null,
"resetMocks": false,
"resetModules": false,
"resolver": null,
"restoreMocks": false,
"rootDir": "/Users/me/Projects/coolproject",
"roots": [
"/Users/me/Projects/coolproject"
],
"runner": "jest-runner",
"setupFiles": [
"/Users/me/Projects/coolproject/node_modules/regenerator-runtime/runtime.js"
],
"setupTestFrameworkScriptFile": null,
"skipFilter": false,
"snapshotSerializers": [],
"testEnvironment": "/Users/me/Projects/coolproject/node_modules/jest-environment-node/build/index.js",
"testEnvironmentOptions": {},
"testLocationInResults": false,
"testMatch": [
"**/__tests__/**/*.js?(x)",
"**/?(*.)+(spec|test).js?(x)"
],
"testPathIgnorePatterns": [
"/node_modules/"
],
"testRegex": "",
"testRunner": "/Users/me/Projects/coolproject/node_modules/jest-jasmine2/build/index.js",
"testURL": "about:blank",
"timers": "real",
"transform": [
[
"^.+\\.jsx?$",
"/Users/me/Projects/coolproject/node_modules/babel-jest/build/index.js"
]
],
"transformIgnorePatterns": [
"/node_modules/"
],
"watchPathIgnorePatterns": []
}
],
"globalConfig": {
"bail": false,
"changedFilesWithAncestor": false,
"collectCoverage": false,
"collectCoverageFrom": null,
"coverageDirectory": "/Users/me/Projects/coolproject/coverage",
"coverageReporters": [
"json",
"text",
"lcov",
"clover"
],
"coverageThreshold": null,
"detectLeaks": false,
"detectOpenHandles": false,
"errorOnDeprecated": false,
"expand": false,
"filter": null,
"globalSetup": null,
"globalTeardown": null,
"listTests": false,
"maxWorkers": 7,
"noStackTrace": false,
"nonFlagArgs": [],
"notify": false,
"notifyMode": "always",
"passWithNoTests": false,
"projects": null,
"rootDir": "/Users/me/Projects/coolproject",
"runTestsByPath": false,
"skipFilter": false,
"testFailureExitCode": 1,
"testPathPattern": "",
"testResultsProcessor": null,
"updateSnapshot": "new",
"useStderr": false,
"verbose": null,
"watch": false,
"watchman": true
},
"version": "23.4.2"
}
I hope this answer helps some other bone-head. I named the babel configuration file babel.rc, not .babelrc. The second one is correct.
I got grunt-contrib-jshint to validate JS files. Problem arises when I change jshint version to other than 0.9.2. Configuration Gruntfile.js
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'<%= config.app %>/scripts/**/*.js',
'!<%= config.app %>/content_scripts/coffee/*'
]
}
and .jshintrc
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": false,
"unused": false,
"strict": false,
}
So when I update to newest version 0.11.2 JSHint works but shows No problems while on 0.9.2 shows couple of various error.
Please help.
I'm using the underscore library.
I get this when running jshint:
[L38:C38] W117: '_' is not defined.
var approvedAndRequstedCount = _.countBy(products, function(obj) {
Warning: Task "jshint:all" failed. Use --force to continue.
This is my config file:
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"angular": false
}
}
I guess it's something with the globals option? I tried to add "_": false but no luck. Any ideas?
I had this issue as well.
I installed underscore: bower install -save underscore and it worked fine in the code. Unfortunately jshint was not finding that reference. You must tell jshint about your global variables in configuration file like .jshintrc:
{
…
"globals": {
"angular": false,
"_": false
}
}
If you continue to have this issue you need to make sure that underscore is included when jshint is executed. I would not recommend setting -W117 to true. Squelching those errors might lead to more bugs.