Parsing error: Invalid regular expression: /\p{Lu}/: Invalid escape (Unicode general category properties) - eslint

ESLint 7.0.0 appears to have a problem with Unicode general category properties in regular expressions.
In one file, I'm getting this error message:
Parsing error: Invalid regular expression: /\p{Lu}/: Invalid escape
I'm getting it in other files as well, but this is the most simple expression on which I'm getting it.
It's a valid expression. Works just fine when I run the code. But it's breaking my ESLint run.
What setting do I use to get ESLint to accept these expressions?

Problem seems to disappear by adjusting .eslintrc.json slightly:
"parserOptions": {
"ecmaVersion": 2019
}

Related

parsing SVG in webpack

I have created a project on Symfony 5. I am receiving an error in webpack when I run 'yarn build'. I am trying to fix it from few days but without success, so I decided to ask for some help :)
This is the error I am getting:
I have enabled postCssLoader in my webpack.config and created postss.config.js in my root directory
.enablePostCssLoader()
postss.config.js File
module.exports = {
plugins: [
require('autoprefixer'),
require('postcss-svgo'),
require('postcss-inline-svg'),
require('postcss-write-svg'),
]
}
And here is a sample of svg I am trying to write in my css
.custom-checkbox .custom-control-input:checked~.custom-control-label::after {
background-image: url('data:image/svg+xml,%3csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'8\'
height=\'8\' viewBox=\'0 0 8 8\'%3e%3cpath fill=\'%23fff\' d=\'M6.564.75l-3.59 3.612-1.538-
1.55L0 4.26l2.974 2.99L8 2.193z\'/%3e%3c/svg%3e')
}
If the error transfers code verbatim, then there are two line breaks (and indentation) that makes the property invalid (see "CRLF": ..width=\'8\'CRLF height.. - this one you can backslash-escape in CSS, and ..1.538-CRLF 1.55L.. - this one with indentation separates numeral making path data invalid - you have to remove all whitespace between minus and digit). If this is it, simply removing line breaks (and suprefluous whitespace) should fix it:
background-image: url('data:image/svg+xml,%3csvg xmlns=\'http://www.w3.org/2000/svg\' width=\'8\' height=\'8\' viewBox=\'0 0 8 8\'%3e%3cpath fill=\'%23fff\' d=\'M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z\'/%3e%3c/svg%3e')
If code snippet you provided is not directly from your source code, then you have probably some formarrter breaking it in the process (?)
N.B. you don't usually have to escape SVG datauris so much, you could go with url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8' fill='%23fff'><path d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26l2.974 2.99L8 2.193z'/></svg>") (i.e. the only escaped sequence is #->%23) and most interpreters should pick it up just fine. I'm not sure about your build stack, but I'd guess that "safe over-escaped format for obsolete IEs" could be produced as the build result; and if you use preprocessor you can embed 'dataurized' external resources, what could prevent such formatting accidents. (Ah, that's probably what the postcss-inline-svg is doing for you.)

How to fix that "Truffle migrate" gets warnings?

I'm trying to set up a blockchain on the operating system macOS, and when I try to do the command "truffle migrate" or "truffle test" I get error messages.
I have tried changing my network id/host/port and nothing works.
Compiling your contracts...
===========================
> Compiling ./contracts/CorderCurrency.sol
> Compiling ./contracts/Migrations.sol
> compilation warnings encountered:
/Users/name/token_sale/contracts/CorderCurrency.sol:9:2: Warning: This declaration shadows an existing declaration.
function CorderCurrency () public {
^ (Relevant source part starts here and spans across multiple lines).
/Users/hanschristianmidelfart/token_sale/contracts/CorderCurrency.sol:3:1: The shadowed declaration is here:
contract CorderCurrency {
^ (Relevant source part starts here and spans across multiple lines).
Error: CompileError: /Users/name/token_sale/contracts/CorderCurrency.sol:9:2: SyntaxError: Functions are not allowed to have the same name as the contract. If you intend this to be a constructor, use "constructor(...) { ... }" to define it.
function CorderCurrency () public {
^ (Relevant source part starts here and spans across multiple lines).
Compilation failed. See above.
at Object.compile (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-workflow-compile/legacy/index.js:72:1)
Truffle v5.0.32 (core: 5.0.32)
Node v10.16.3```

Getting "Parsing error: 'return' outside of function"

I am trying to lint and I am getting...
Parsing error: 'return' outside of function
This is in a markdown document so it should be ignored. How do I explicitly ignore this rule?

How to format chocolatey params in puppet manifest

The following choco install command works fine:
choco Install 'InstallTest' -y --source 'C:\installtest' --params="'/serverinstance:MyServer /buildtype:OTP'"
I now have the following, in a Puppet manifest:
package { 'InstallTest':
ensure => installed,
install_options => ['-params','"', /serverinstance:MyServer, /buildtype:OTP, '"'],
source => 'c:\installtest',
}
I thought that I was correctly covering spaces with commas, etc, but puppet parser throws the following error:
puppet : [1;31mError: Could not parse for environment production: invalid byte sequence in UTF-8[0m
Without the install_options line, it compiles fine.
What should the correct syntax be?
The problem is here:
install_options => ['-params','"', /serverinstance:MyServer, /buildtype:OTP, '"'],
Although Puppet can accept bare words as strings, there are limitations on the content of such strings. The one relevant here is that they must
Begin with a lower case letter, and contain only letters, digits, hyphens (-), and underscores (_).
Thus, you're looking for this:
install_options => ['-params', '"', '/serverinstance:MyServer', '/buildtype:OTP', '"'],
Overall, its better style to quote substantially all strings, whether they need it or not. That's clearer, and it will keep you out of trouble.

How do you disable no-plusplus when using eslint?

When using eslint in Visual Studio Code, AirBnB style Ubuntu Linux, no-plusplus is enabled as default so using ++ for example in a for loop will error: [eslint] Unary operator '++' used. (no-plusplus)
How do you disable that setting?
You can just override it in your .eslintrc.js file as follows:
'no-plusplus': 'off'
or if you don't want to disable it completely but only for for-loops:
'no-plusplus': [2, { allowForLoopAfterthoughts: true }]
You can also write variable += 1 instead, as suggested by ESLint.
You can locate the file location you need to alter on Linux by searching for the keyword using grep, in this case to search for the file containing plusplus when in the folder eslint was installed use
grep -r plusplus
The correct file will be the eslint-config file, in this case it should be: node_modules/eslint-config-airbnb-base/rules/style.js
To disable the setting comment out the no-plusplus line, you can easily re-enable if required:
// 'no-plusplus': 'error',
Or you can go like this:
'no-plusplus': 0,
You can simply write your declared variable += 1 instead, as suggested by ESLint.
varible++ is similar as variable+=1.

Resources