Eslint rule: validate blanks in a variable declaration - eslint

Validate this statement: (space between the variable, the = and the string)
wrong
let mystring="Lorem Ipsum is simply dummy text of the printing and typesetting industry."
good
let mystring = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."
I've been looking for a rule to validate that in the documentation but I can't find anything about it
UPDATE
The rule to validate this is:
https://eslint.org/docs/rules/space-infix-ops

You can use the prettier for code formatting and code beautify. This is very helpful. You can read the documentation and get to know its features. You can use in IDE as well as in the build.

Related

Remove Sub-String of Pattern from a String in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a string, say
s1 = '<h3><a id="_a50ezru0fkt"></a>Overview</h3><p>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text</p><h3><a id="_a50ezpu0fgr"></a><p>is simply dummy text of the pr</p>'
I need to remove all the empty <a> tag from s1 There can be several such empty <a> tag in the string where id can take any value.
So that final result is:
s1 = '<h3>Overview</h3><p>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text</p><h3><p>is simply dummy text of the pr</p>'
I would like to achieve this using regular expression, please.
Does something like this help?
import re
s1 = '<h3><a id="_a50ezru0fkt"></a>Overview</h3><p>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text</p><h3><a id="_a50ezpu0fgr"></a><p>is simply dummy text of the pr</p>'
s2 = re.sub(r'(<a.*?></a>)', '', s1)
print(s2)
'''<h3>Overview</h3><p>is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text</p><h3><p>is simply dummy text of the pr</p>'''

How to test in cucumber-js a that a result is a multi line string?

I would like to test whenver the result of a step has a certain value, but this value is a multiline string that contains |, - and any special characters.
The string can look like:
{ ------- }|
{aaaaaaaaaa|
{aaaaaaaaaa|
I'm not sure how can I do it in a feature as this will throw me a syntax error:
Feature: asdada
Scenario: test
Given test
When test
Then the result is:
{ ------- }|
{aaaaaaaaaa|
{aaaaaaaaaa|
Example from Is it possible to write a gherkin step on multiple lines?
thanks to Grasshopper for answering this.
Given a blog post named "Random" with Markdown body
"""
Some Title, Eh?
==============
Here is the first paragraph of my blog post. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
"""
Don't do this, you are just making your scenario really fragile. Instead give the string a name and use that name in the scenario e.g. Then I should see the foo result. Now you can delegate the string comparison to the step definition, and define what the foo result is however you choose.
Scenarios are about documenting what you are doing and why its important. The format of results is all about how you are doing things. If you put the how in scenarios then every time you change how you do something you have to change scenarios. This makes small changes much more expensive.

Is it possible to write a gherkin step on multiple lines?

I am new to the Gherkin language and this seems to me like very basic question but I could not find answer to it.
I am aware that it is possible to write multi-line step argument in Gherking, like this:
Given a blog post named "Random" with Markdown body
"""
Some Title, Eh?
==============
Here is the first paragraph of my blog post. Lorem ipsum dolor sit amet,
consectetur adipiscing elit.
"""
My question is about writing single step on multiple lines, something like this:
Given that Gherkin language allows me to write my step definitions \
on multiple lines
Then my test cases would be easier to read :)
In the example above I used '\' as line continuation symbol. BTW, I tried the example above and got parser error.
Yes, we can write a gherkin step on multiple lines using triple set of double quotes ("""). Gherkin recognizes the triple set of double quotes as the bounding delimiters for the multi-line string and passes it in. Whatever content you write between triple set of double quotes will be passed to your step definition as a single string.
As in my current capybara project, I have written gherkin step on multiple lines as shown below:
Scenario: Some test scenario
Given Bob is on "www.abc.com"
When Bob creates team "Test Team"
Then Bob sees message:
"""
As the Team Captain you will be responsible for paying for the team after
registration closes. You will be emailed instructions at the close of
registration.
"""
And Bob clicks "Next" button
Step definition for multi line gherkins step:
And(/^(\S*) sees message:$/) do |user, message|
page.should have_content(message)
end
In this I have used the content passed as it is. You can also split your content and use as required.
For more information please refer to below mentioned link:
http://asymmetrical-view.com/2011/06/02/cucumber-gherkin-and-multiline-arguments.html
Hope this helps :)
You tried and got a parse error. I assume that writing the long line on a single line did not give you a parse error. You have therefore answered your own question with no.
I would like to suggest that you ask yourself why the lines has to be long. The wanted behaviour, does it really need so many details that the line gets very long?
It is often possible to express your self shorter by rephrasing a sentence. It is also possible that you could break the long sentence by using the Gherkin keywords And or But.

Preserving newlines in Jade

Whenever I render a JADE template, I get all HTML in a single line. This makes it difficult to read in view-source mode. How can I tell JADE to create HTML which is properly indented?
Here is my template:
#application
p#docs
a(href='/docs/index.html') Documentation
p#user-input
input#msg(name='msg', size='50')
input#submit(name='submit', type='submit', value='Send a Message')
ul#messages
In Jade's compiling options set pretty to true.
Which can be done in multiple ways depending of how you are compiling them
From the command line pass the -P or --pretty flag.
From express 3.x: app.locals.pretty = true;
(express 2.x used a different syntax: app.set('view options', { pretty: true });, see migration guide: https://github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x)
Then you can do the following
#test. // <-- notice the dot
Lorem Ipsum is simply dummy text of
the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s ,
when an unknown printer took a galley of type and scrambled
which will produce
<div id="test">
Lorem Ipsum is simply dummy text of
the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s ,
when an unknown printer took a galley of type and scrambled
</div>

How do I do a multi-line string in node.js?

With the rise of node.js, multi-line strings are becoming more necessary in JavaScript.
Is there a special way to do this in Node.JS, even if it does not work in browsers?
Are there any plans or at least a feature request to do this that I can support?
I already know that you can use \n\ at the end of every line, that is not what I want.
node v4 and current versions of node
As of ES6 (and so versions of Node greater than v4), a new "template literal" intrinsic type was added to Javascript (denoted by back-ticks "`") which can also be used to construct multi-line strings, as in:
`this is a
single string`
which evaluates to: 'this is a\nsingle string'.
Note that the newline at the end of the first line is included in the resulting string.
Template literals were added to allow programmers to construct strings where values or code could be directly injected into a string literal without having to use util.format or other templaters, as in:
let num=10;
console.log(`the result of ${num} plus ${num} is ${num + num}.`);
which will print "the result of 10 plus 10 is 20." to the console.
Older versions of node
Older version of node can use a "line continuation" character allowing you to write multi-line strings such as:
'this is a \
single string'
which evaluates to: 'this is a single string'.
Note that the newline at the end of the first line is not included in the resulting string.
Multiline strings are a current part of JavaScript (since ES6) and are supported in node.js v4.0.0 and newer.
var text = `Lorem ipsum dolor
sit amet, consectetur
adipisicing
elit. `;
console.log(text);
What exactly are you looking for when you mean multiline strings.
Are you looking for something like:
var str = "Some \
String \
Here";
Which would print as "Some String Here"?
If so, keep in mind that the above is valid Javascript, but this isn't:
var str = "Some \
String \
Here";
What's the difference? A space after the \. Have fun debugging that.
As an aside to what folks have been posting here, I've heard that concatenation can be much faster than join in modern javascript vms. Meaning:
var a =
[ "hey man, this is on a line",
"and this is on another",
"and this is on a third"
].join('\n');
Will be slower than:
var a = "hey man, this is on a line\n" +
"and this is on another\n" +
"and this is on a third";
In certain cases. http://jsperf.com/string-concat-versus-array-join/3
As another aside, I find this one of the more appealing features in Coffeescript. Yes, yes, I know, haters gonna hate.
html = '''
<strong>
cup of coffeescript
</strong>
'''
Its especially nice for html snippets. I'm not saying its a reason to use it, but I do wish it would land in ecma land :-(.
Josh
In addition to accepted answer:
`this is a
single string`
which evaluates to: 'this is a\nsingle string'.
If you want to use string interpolation but without a new line,
just add backslash as in normal string:
`this is a \
single string`
=> 'this is a single string'.
Bear in mind manual whitespace is necessary though:
`this is a\
single string`
=> 'this is asingle string'
Take a look at the mstring module for node.js.
This is a simple little module that lets you have multi-line strings in JavaScript.
Just do this:
var M = require('mstring')
var mystring = M(function(){/***
Ontario
Mining and
Forestry
Group
***/})
to get
mystring === "Ontario\nMining and\nForestry\nGroup"
And that's pretty much it.
How It Works
In Node.js, you can call the .toString method of a function, and it will give you the source code of the function definition, including any comments. A regular expression grabs the content of the comment.
Yes, it's a hack. Inspired by a throwaway comment from Dominic Tarr.
note: The module (as of 2012/13/11) doesn't allow whitespace before the closing ***/, so you'll need to hack it in yourself.
Take a look at CoffeeScript: http://coffeescript.org
It supports multi-line strings, interpolation, array comprehensions and lots of other nice stuff.
If you use io.js, it has support for multi-line strings as they are in ECMAScript 6.
var a =
`this is
a multi-line
string`;
See "New String Methods" at http://davidwalsh.name/es6-io for details and "template strings" at http://kangax.github.io/compat-table/es6/ for tracking compatibility.
Vanilla Javascipt does not support multi-line strings. Language pre-processors are turning out to be feasable these days.
CoffeeScript, the most popular of these has this feature, but it's not minimal, it's a new language. Google's traceur compiler adds new features to the language as a superset, but I don't think multi-line strings are one of the added features.
I'm looking to make a minimal superset of javascript that supports multiline strings and a couple other features. I started this little language a while back before writing the initial compiler for coffeescript. I plan to finish it this summer.
If pre-compilers aren't an option, there is also the script tag hack where you store your multi-line data in a script tag in the html, but give it a custom type so that it doesn't get evaled. Then later using javascript, you can extract the contents of the script tag.
Also, if you put a \ at the end of any line in source code, it will cause the the newline to be ignored as if it wasn't there. If you want the newline, then you have to end the line with "\n\".

Resources