Why JSLint is producing this kind of warning
Problem at line xxx character yyy: Expected 'X' to have an indentation at xx instead at yyy.
Why does it matter to have a different space formatting?
Well, since you didn't show us the line, we can only guess, but it's probably something like this.
if(someCondition)
DoThis();
DoThat();
Since it would expect the indenting to be:
if(someCondition)
DoThis();
DoThat();
It thinks you may want it to be:
if(someCondition)
{
DoThis();
DoThat();
}
You have indented something that shouldn't be indented, or shouldn't be indented as much.
This often happens after declaring several variables:
var foo,
bar;
baz = something;
or with if statements as #James Curran mentioned. Just go to line xxx and see if something is indented that shouldn't be. If you can't find it, post the section og the code in the question and let us have a look.
As James points out, it's likely a spacing issue.
var spam = 3;
if (3 === spam) {
spam = 4;
}
... gives me Expected 'spam' at column 5, not column 1.
If whitespace isn't something you want JSLint to check (and it generally isn't for me), you have two choices to turn off "sloppy whitespace" checks. On the site (or in your tool of choice), you can check "white", or you can add a directive at the top of your file, like this:
/*jslint white:true*/
var spam = 3;
if (3 === spam) {
spam = 4;
}
Now I get a clean bill o' lint.
Related
I am trying to understand this code:
https://github.com/CameronAavik/AdventOfCode/blob/master/Challenges/2018/Day03.fs
But I couldn't find any info about this "let something (...) { ... } = ..."syntax, for example:
let processBoundary (prevY, claimSet, total) {cursor=cursor; isAdding=isAdding; data=(top, height)} = ...
what is this? reminds me to a tuple and destructuring, but maybe it is not that.
thanks
It is actually destructuring as with a tuple, just that it's a record in this case.
A notable difference is that while with a tuple you have to match the exact number and position of the individual parts, when destructuring a record, you can leave out any of the fields you're not interested in at that point.
I wrote a (non-exhaustive) blog post on different ways of pattern matching/destructuring in F# once; maybe that's helpful in understanding here.
Is there an efficient algorithm for finding broken parenthesis in a block of text for the purpose of intellisense error highlighting?
For instance:
function f() {
var a = [1, 2, 3];
if ((a[1] < 1) || (a[0] > 2)) {
console.log((a + 5).toString());
}
}
Where any (, ), [, ], {, or } character might be dropped or adding in correctly and the correct issue might be highlighted, for instance spotting the specific statement, function, conditional, etc level item causing the issue?
The algorithm is not difficult:
Have a stack of characters
For each character in the code:
If it's an opening bracket, push it onto the stack
If it's a closing bracket, pop one char from the stack, both must match
At the end the stack must be empty
Then you could maybe highlight the unmatched bracket(s).
I think that one way of approaching your problem is to validate the matching bracket groups. This may be achieved using the regular expression - see: http://blog.stevenlevithan.com/archives/javascript-match-nested of Steven Levithan.
I was looking for a solution to a regex problem in Rails I had and an answer on a separate question lead me 90% of the path to the answer. Basically, what I would like to do is to have a ruby/rails script that will format a messy text in terms of capitalizing every letter after a "./,/!/?". This code by "Mark S"
ng = Nokogiri::HTML.fragment("<p>hello, how are you? oh, that's nice! i am glad you are fine. i am too.<br />i am glad to have met you.</p>")
ng.traverse{|n| (n.content = n.content.gsub(/(.*?)([\.|\!|\?])/) { " #{$1.strip.capitalize}#{$2}" }.strip) if n.text?}
ng.to_s
The only issue I have with this code, and it is a big issue, is that the code adds a space in between float numbers like "2.0", making a text like:
there is a cat in the hat.it has a 2.0 inch tail!
isn't that awesome?!I think so.
Become
There is a cat i the hat. It has a 2. 0 inch tail!
Isn't that awesome?! I think so.
where I obviously want it to be:
There is a cat i the hat. It has a 2.0 inch tail!
Isn't that awesome?! I think so.
Any suggestions on how to alter this text, for example so that any "." will be ignored by this code?
It seems you want to capitalize any lowercase letter at the beginning of the string or after ., !, or ?.
Use
s.gsub(/(\A|[.?!])(\p{Ll})/) { Regexp.last_match(1).length > 0 ? "#{$1} #{$2.capitalize}" : "#{$2.capitalize}" }
See the Ruby demo
Pattern details:
(\A|[.?!]) - Group 1 capturing the start of string location (empty string) or a ., ?, or !
(\p{Ll}) - Group 2 capturing any Unicode lowercase letter
Inside the replacement, we check if Group 1 value is not empty, and if it is, we just return the capitalized letter. Else, return the punctuation, a space, and the capitalized letter.
NOTE: However, there is a problem with abbreviations (as usual in these cases), like i.e., e.g., etc. Then there are words like iPhone, iCloud, eSklep, and so on.
I have the following code which enables me to make console output appear on the same line. However, if a value that was previously printed was of greater length than values after it, the remnants of the longer value will show up. I have seen other questions about the same thing in languages like Python, but I'm not sure how to overcome this in Rust.
Here's an example:
use std::io::prelude::*;
fn main() {
let fruits = ["Blueberry", "Orange", "Cherry", "Lemon", "Apple"];
print_value(&fruits);
}
fn print_value(e: &[&str]) {
for val in e {
print!("\rStatus: {}", val);
std::io::stdout().flush().unwrap();
// pause program temporarily
std::thread::sleep(std::time::Duration::new(2, 0));
}
}
Some terminals have a special character sequence that, when printed, clears the line to the right of the current cursor position.
VT100-compatible terminals have a character sequence EL0 for that. In Rust it can be expressed with "\x1B[K".
Here's a little thingy that might prove an example.
To do that in a more portable way you use a terminal library, such as term and it's delete_line method.
I use JSLint and have a huge library of code that is 100% JSLint clean. As of 1.20.2011, JSLint reports errors whitespacing errors on every var statement. Take, for example, this (now hollowed out) function:
var dateStrFromTimestamp;
dateStrFromTimestamp = function (t) {
"use strict";
var a, d;
d = new Date(t * 1000);
a = [];
};
JSLint reports:
Problem at line 1 character 5: Expected 'dateStrFromTimestamp' at column 3, not column 5.
var dateStrFromTimestamp;
Problem at line 4 character 7: Expected 'a' at column 5, not column 7.
var a, d;
How am I supposed to write my code? If I follow the recommendation, I'd have to remove the whitespace after the keyword "var" -- but that can't be. So, is the current version of JSLint buggy? Or am I currently blind to something obvious?
Looks like he's fixed it. I continued getting the problem, then did a Shift+refresh to clear his JS file from my cache, and that seemed to fix it I think.
This is probably because you mixed tabs ans spaces, and JSLint supposes that a tab is the equivalent of 4 spaces.