eslint Failures in Travis CI, but not locally - node.js

I have a GitHub project that has passed Travis CI. Upon creating a pull request for a new feature, Travis CI fails both pr and push due to two eslint errors:
/home/travis/build/enove/Thriver/packages/thriver-accounts/lib/accounts.js
121:5 error Strings must use singlequote quotes
122:5 error Strings must use singlequote quotes
Lines 119 through 122 of accounts.js are as follows:
119: return `Hello ${user.profile.firstname}!\n\n` +
120: `To verify your account email, simply click the link below.\n\n${url}\n\n` +
121: `If you weren't expecting this email, simply delete it.\n\n` +
122: `Thanks!\n\nAll of us at WCASA`;
The commit did not even change accounts.js, and a local eslint passes without error. I checked and verified that the versions of node, npm, and meteor are the same locally as they are in Travis CI.
The Travis CI configuration is as follows:
{
"sudo": "required",
"language": "node_js",
"node_js": "4.1.1",
"before_install": [
"curl -L https://git.io/ejPSng | /bin/sh"
],
"env": "CXX=g++-4.8",
"addons": {
"apt": {
"sources": [
"ubuntu-toolchain-r-test"
],
"packages": [
"g++-4.8"
]
}
},
"services": "mongodb",
"script": [
"meteor npm run lint"
],
"group": "stable",
"dist": "precise",
"os": "linux"
}
The .eslintrc is as follows:
{
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"impliedStrict": true
}
},
"env": {
"browser": true,
"node": true,
"mongo": true,
"meteor": true
},
"extends": [
"airbnb"
//"plugin:meteor/recommended"
],
"globals": {
"Thriver": true,
"SimpleSchema": true,
"Marked": true,
"SHA256": true,
"google": true,
"geoXML3": true,
"AutoForm": true,
"details_shim": true
},
"rules": {
"no-underscore-dangle": 0,
"new-cap": 0
}
}
This has happened before in a different file and I "resolved" the issue by having eslint ignore the line. But I can't do that for every mystery issue. Any advice?

http://eslint.org/docs/rules/quotes
This is most likely the fix to your problem.
JavaScript allows you to define strings in one of three ways: double quotes, single quotes, and backticks (as of ECMAScript 6). For example:
/*eslint-env es6*/
var double = "double";
var single = 'single';
var backtick = `backtick`; // ES6 only
The choice of how to define strings in a codebase is a stylistic one outside of template literals (which allow embedded of expressions to be interpreted). Many codebases require strings to be defined in a consistent manner.
I would try setting one of these rules and running the tests again.
Let me know if this does not fix your problem!

I still have no idea how eslint was passing locally. Perhaps I was behind in eslint or airbnb version. However, I realized that the lines really did need to be corrected. The bottom two lines of code should not use back ticks because there aren't any variables in those strings.
119: return `Hello ${user.profile.firstname}!\n\n` +
120: `To verify your account email, simply click the link below.\n\n${url}\n\n` +
121: 'If you weren\'t expecting this email, simply delete it.\n\n' +
122: 'Thanks!\n\nAll of us at WCASA';
Eslint is a lot happier with a concatenated string of different styles than a consistent one where not every segment contains a variable.

Related

How to override ava test runner's env variables while testing?

Ava test runner in my project has its own env variables defined like this in package.json:
"ava": {
"require": [
"esm"
],
"files": [
"test/unit/**/**/ava-*"
],
"environmentVariables": {
"SERVER_DEFAULT_TIMEZONE": "Australia/Sydney",
"PAY_MAX": "false",
"NODE_ENV": "development"
},
"timeout": "20s"
},
Now when doing a unit test for a certain file it happens that I need to cover this line in the function that I'm testing:
const isPayMax = process.env.PAY_MAX === "true";
So I'm trying to make that condition true so I can cover in my test. However, no matter I tried setting it to "true" or any other value, it still keep the value defined in package.json.
I've also tried using rewire module but it doesn't seem to work as well.
Also tried setting manually the environment variable in my test file like this process.env.PAY_MAX = "true" but no luck as well.
Any thoughts on how to deal with this? Thanks.

ESLint conflicts with eslint-plugin-import and typescript-eslint

I want to include the rule no-unpublished-import from eslint-plugin-node, however, it is conflicting with my current .eslintrc because I am using typescript-eslint and eslint-import-resolver-typescript.
It is my current configuration:
{
"parser": "#typescript-eslint/parser", // Specifies the ESLint parser
"extends": [
"airbnb-base",
"plugin:#typescript-eslint/recommended", // Uses the recommended rules from the #typescript-eslint/eslint-plugin
"prettier", // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array
"prettier/#typescript-eslint" // Uses eslint-config-prettier to disable ESLint rules from #typescript-eslint/eslint-plugin that would conflict with prettier
],
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 6, // Allows for the parsing of modern ECMAScript features
"sourceType": "module" // Allows for the use of imports
},
"rules": {
},
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".ts"]
},
// use <root>/tsconfig.json
"typescript": {
"alwaysTryTypes": true // always try to resolve types under `<root>#types` directory even it doesn't contain any source code, like `#types/unist`
}
}
},
"root": true
}
The code compiles correctly, however, if I add to the extends option the plugin:node/recommended the compilation process will fail:
1:1 error Import and export declarations are not supported yet node/no-unsupported-features/es-syntax
1:43 error "express" is not found node/no-missing-import
2:1 error Import and export declarations are not supported yet node/no-unsupported-features/es-syntax
My package.json includes the node": ">=12.0.0. Also, this rule should be ignored because I am using typescript. On the other hand, I am just exporting types from express because the module don't use it.
According to this issue the conflict should be resolved by eslint-plugin-node.
How can I accomplish the merge of both plugins? Do I have to go disabling rules one by one?
UPDATED:
It seems it was asked in this issue on the eslint-plugin-node repository. It works for no-unsupported-features and no-missing-import, however, it is still failing with the import definition of express with no-extraneous-import.
UPDATED 2:
It seems eslint-plugin-node is working on a enhancement to accomplish it. Issue here
Firstly, you have to add the option tryExtension to include TS files:
"settings": {
"node": {
"tryExtensions": [".js", ".json", ".node", ".ts", ".d.ts"]
},
To solve the no-unsupported-features/es-syntax, according to this issue about adding information to works with TypeScript, if you work with transpilers you will have to ignore it under rules:
"node/no-unsupported-features/es-syntax": ["error", { "ignores": ["modules"] }],
On the other hand, use just types and not the code is not supported yet by the eslint-plugin-node. They are working on a enhancement to solve it. However,, to solve the no-missing-import, you have to add to the resolvePath the node_modules/#types:
"node": {
"resolvePaths": ["node_modules/#types"],
"tryExtensions": [".js", ".json", ".node", ".ts", ".d.ts"]
},
Even so, it will generate a no-extraneous-import because it doesn't detect the module, because it is just a type. Meanwhile they are working on this enhancement, you can use allowModules under that rule for workaround:
"node/no-extraneous-import": ["error", {
"allowModules": ["express"]
}]

.eslintrc: Configuration for rule "import/extensions" is invalid:

First things first, I have some basics but I don't consider myself as a developer at all :p
Here's my problem: I cloned a repo ( this one ) in order to work on a brand new portfolio and test the whole enchilada, but i ran into some errors, as I'm not familiar at all with the eslint setup.
After cloning the repo, I try to gatsby develop and I ran into a few error messages like this one:
Generating development JavaScript bundle failed
/home/asus/code/chrisnopa/gatsby-projects/portf-boilerplate/src/hoc/withProvider.js
4:25 error Missing file extension for "store/createStore" import/extensions
✖ 1 problem (1 error, 0 warnings)
File: src/hoc/withProvider.js
Here's the content of my .eslintrc file :
"parser": "babel-eslint",
"env": {
"browser": true,
"jest": true,
"es6": true,
"node": true
},
"extends": [
"airbnb",
"prettier"
],
"plugins": [
"prettier"
],
"globals": {
"graphql": true
},
"rules": {
"react/jsx-filename-extension": 0,
"react/require-default-props": 0,
"react/jsx-one-expression-per-line": 0,
"arrow-body-style": 0,
"import/no-unresolved": 0,
"prettier/prettier": ["error", {
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}]
}
}
I added this line to the part "Rules" : "import/extensions": [".js", ".jsx", ".json", ".ts", ".tsx"]
and it fixed everything except for one error. Here is the message in my console :
Generating development JavaScript bundle failed
.eslintrc:
Configuration for rule "import/extensions" is invalid:
Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '".js"').
File: src/pages/index.js
failed Building development bundle - 4.029s
Any idea on what I am doing wrong here, and on how to fix this would be much appreciated!
Updated eslint-plugin-import to v2.11.0 (or above)

Turn off error for console.log on my eslint

I'm trying to turn off lint warning for my eslint at VS code.
My code is contains.
console.log('blabla..');
eslint said as below.
error Unexpected console statement no-console
Even though already add no-restricted-syntax at my .eslintrc.json, no fixed.
Here is my .eslintrc.json
{
"env": {
"es6": true,
"node": true,
"amd": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"rules": {
"linebreak-style": [
"error",
"windows"
],
"no-restricted-syntax": [
"error",
{
"selector": "CallExpression[callee.object.name='console'][callee.property.name=/^(log|warn|error|info|trace)$/]",
"message": "Unexpected property on console object was called"
}
]
}
}
What did I mistake?
Allowing the console.log to stay in code is requiring a separate rule.
You need to add 'no-console' statement to your eslint config rules.
Like so:
rules: {
"no-console": 0
}
A better practice is to warn you about all the console.log in your code, like so:
rules: {
"no-console": 1
}
I followed the advice of Elad and went into the package.json to add the rule of "no-console": 0 and at first it didn't seem like it worked but this is because I needed to restart the development server. If it seems like it's not working, make sure you restart the development server because if you change anything in the package-json, you have to restart your server.
You can add // eslint-disable-line if you need to ignore a specific (or multiple) line

NODE_PATH is consumed by atom, it replaces my already in place NODE_PATH

I'm on a windows 10 environment writing a plugin for the Atom text editor to allow running tests through protractor cucumber from within atom it consumes the PlatformIO-Terminal plugin's provided service. When I activate that terminal plugin from within Atom I'd expect to be able to execute any old program from it that I could from my terminal that it's emulating through pty.
I'm having trouble executing any node program I've installed via npm outside of Atom's apm. Further digging via printing the environment variable NODE_PATH from within that terminal revealed that Atom has eaten my NODE_PATH value, not appended it's own but completely consumed and replaced it. Resetting it from within that pty window doesn't work, and neither does adding it to the "Shell Environment Variables" from within the PlatformIO configuration terminal. I've installed 3 plugins which allow pulling in environment variables from the OS, and none of them have succeeded.
Is there a way to solve this problem? I can access the executable modules directly, but they call other ones and depend on NODE_PATH.
If you aren't having success with terminal packages, you might try process-palette. It allows you to precisely define all of the details of the command, including environment variables. I've made an Atom command that sets NODE_ENV to an arbitrary string before executing a terminal command. Screenshots below:
Below is a process-palette.json file that defines the command I wrote. All you have to do to get started is install the package, make that file with the following code, and select Packages -> Process Palette -> Edit Configuration.
{
"patterns": {
"P1": {
"expression": "(path):(line)"
},
"P2": {
"expression": "(path)\\s+(line)",
"path": "(?:\\/[\\w\\.\\-]+)+"
}
},
"commands": [
{
"namespace": "process-palette",
"action": "env",
"command": "echo %NODE_PATH%",
"arguments": [],
"cwd": null,
"inputDialogs": [],
"env": {
"NODE_PATH": "wargarble"
},
"keystroke": null,
"stream": true,
"outputTarget": "panel",
"outputBufferSize": 80000,
"maxCompleted": 3,
"autoShowOutput": true,
"autoHideOutput": false,
"scrollLockEnabled": false,
"singular": false,
"promptToSave": true,
"saveOption": "none",
"patterns": [
"default"
],
"successOutput": "{stdout}",
"errorOutput": "{stdout}\n{stderr}",
"fatalOutput": "Failed to execute : {fullCommand}\n{stdout}\n{stderr}",
"startMessage": null,
"successMessage": "Executed : {fullCommand}",
"errorMessage": "Executed : {fullCommand}\nReturned with code {exitStatus}\n{stderr}",
"fatalMessage": "Failed to execute : {fullCommand}\n{stdout}\n{stderr}",
"menus": [
"env"
],
"startScript": null,
"successScript": null,
"errorScript": null,
"scriptOnStart": false,
"scriptOnSuccess": false,
"scriptOnError": false,
"notifyOnStart": false,
"notifyOnSuccess": true,
"notifyOnError": true,
"input": null
}
]
}

Resources