After grunt-jscs it gives following errors for base/index.js file.
Running "jscs:src" (jscs) task
validateLineBreaks: Invalid line break at api/v1/base/index.js :
1 |var errors = require('restify-errors');
-----------------------------------------------^
2 |function Base(Model) {
After I remove var errors = require('restify-errors'); this line, it starts giving below error
Running "jscs:src" (jscs) task
validateLineBreaks: Invalid line break at api/v1/base/index.js :
1 |function Base(Model) {
------------------------------^
How to resolve this?
Workaround found : Created new file and copied all content to it resolves the problem.
Still want to know any specific reason why this is happening?
this is probably an issue with line breaks
You might want to put "validateLineBreaks": null into your .jscsrc file
If your .jscsrs is with the rule
"validateLineBreaks":"LF",
It means you must use LF as line breaks, if you are using other line break symbol (such as CRLF), JSCS will give you an error like:
validateLineBreaks: Invalid line break at api/v1/base/index.js :
There're two ways to resolve the problem, one is to change the jscs' rule, and the other is to always use LF as line breaks.
You can find the different between LF and CR in this link:
https://en.wikipedia.org/wiki/Newline
tldr;
Change between LF an CRLF, if you are using VScode you can do this by clicking the option at the bottom right:
Detailed: As tomato said, the issue is probably that the line break format of your IDE isn't compatible with jscs, from the eslint documentation:
The linebreaks (new lines) used in windows operating system are
usually carriage returns (CR) followed by a line feed (LF) making it a
carriage return line feed (CRLF) whereas Linux and Unix use a simple
line feed (LF). The corresponding control sequences are "\n" (for LF)
and "\r\n" for (CRLF)
You can also try adding *.js text eol=lf to your .gitattributes file if you know this won't affect the project in any meaningful way.
You can read more about the issue here: https://eslint.org/docs/rules/linebreak-style
Related
An HL7 message comes into Mirth and throws a "processing" error. At the very bottom of the message in Raw format is a partial line that has been separated from the line above it. I have to manually correct this every time. I am hoping to use a Mirth-Javascript as a message filter that can fix this so that everything flows without human intervention.
Below message snippet triggers the error. In this example it is the very last line of the HL7 message.
OBX|68|FT|PT6663&IMP^PET/CT Imaging Whole Body||
||||||F|||202254836969552|||
Currently my only fix is to open the HL7 message and manually go to the line break and bring it up to the line above it that is part of the segment.
The HL7 message should look like this:
OBX|68|FT|PT1103&IMP^PET/CT Imaging Whole Body||||||||F|||20190327101958|||
This worked. Put the following into the preprocessor.
message = message.replace(/[\r\n]+(?![A-Z][A-Z][A-Z0-9]\|)/g, "");
return message;
Remove all line brakes in the channel's pre-processor or attachment script, and then insert them back based on the segment names.
The best way would be to stop the message generating system insert line brakes into OBX.5 field.
Removing all line breaks would be an approach, but it could be a problem later on, you could set up a replace script, that instead of '/n', searches for '|/n|' or a similar string, that way, it would fix that particular problem as well as any other undesired line breaks in between vertical separators, tho it wouldnt help if it broke anywhere else, so keep that in mind.
Put this code snippet in your preprocessor script. It worked for me
var newmessage = message.replace(/[\n\r]$/,"");
while (newmessage.match(/(\r\n|\r|\n)([^A-Z]|[A-Z][^A-Z]|[A-Z]{2}[^A-Z\d]|[A-Z]{2}[\d][^|]|[A-Z]{3}[^|])/i)) {
var extrabit = newmessage.match(/(\r\n|\r|\n)([^A-Z]|[A-Z][^A-Z]|[A-Z]{2}[^A-Z\d]|[A-Z]{2}[\d][^|]|[A-Z]{3}[^|])/i)[0].substring(1);
var newmessage = newmessage.replace(/(\r\n|\r|\n)([^A-Z]|[A-Z][^A-Z]|[A-Z]{2}[^A-Z\d]|[A-Z]{2}[\d][^|]|[A-Z]{3}[^|])/i,'\\.br\\' + extrabit);
}
return newmessage;
Mirth processor expects every line the first 3 characters should contain valid HL7 segments otherwise the mirth throws an error.
To remove the invalid line breaks in the HL7 message you should follow the below steps.
1.Channel -->Scripts -->Preprocessor.
Paste the bellow code top of the "return message;" statement
message = message.replace(/[\r\n]+(?![A-Z][A-Z][A-Z0-9]\|)/g, ""); //This Line is for invalid line breaks in incoming message APPEND to PREVIOUS SEGMENT .
Save the changes and deploy the channel for new changes affected.
From your question, the HL7 field that contains line breaks is OBX(5,1) which should hold Observation Value.
Observation value may contain line breaks as a part of data. Line break (<CR> or ASCII 13) is segment separator by default. If this is received as a part of data, there will be issues while parsing message. This is the root cause of the problem you mentioned in the question.
The segment separator is not negotiable. It is always a carriage return. I have explained this in more details in this answer.
Ideally, those line breaks should be replaced with its escape sequence while building HL7 message. More details about it are already given in one of my earlier answers here.
So, your inbound message
OBX|68|FT|PT6663&IMP^PET/CT Imaging Whole Body||
||||||F|||202254836969552|||
should be actually
OBX|68|FT|PT6663&IMP^PET/CT Imaging Whole Body||\X0D\\X0D\||||||F|||202254836969552|||
About your actual question that how to do this with Mirth/Javascript, there should not be need in your particular use case. This conversion should be done before sending message to Mirth. So, the one who is sending this message to you should build it like this.
While actually displaying observation value on UI, you again need to do the reverse process.
Edit:
If line break is different than <CR> (ASCII 13), then respective HEX should be replaced in \X0D\. Details are mentioned in my linked answer; I am not repeating those here.
I had the similar issue of having blank lines between the segments and i solved it liked this :
content = content.replace(/^\s*\n/gm, '');
Note: This will just remove blank lines. You need to still figure out how to get the next line on current line
You can try regex to eliminate all '\n' not followed by any segment.
In my project,I use antlr4 to extract strings in javascript files.
I use the open source grammar ECMAScript.g4 file(the runtime is python2) and the url of this file is
https://github.com/antlr/grammars-v4/tree/master/ecmascript/Python
after running the g4 file with command:
antlr4 -Dlanguage=Python2 ECMAScript.g4
I got several python files:lexer、listener、tokens and so on.
and in ECMAScriptListener.py I find a function enterLiteral
def enterLiteral(self, ctx):
in this function I can get the strings, thus I add
print 'text:',ctx.getText()
to test.
But I found that some files can be parsed correctly(all strings were printed),and some files(like jquery-3.1.1.min.js)will throw errors like
line 2:200 rule returnStatement failed predicate: {!this.here(ECMAScriptParser.LineTerminator)}?
line 2:250 missing ')' at ','
finally the strings before the error position will be printed,but the strings after the error position will not.I don't know why this happen and how to solve it.
(Sorry I have not learned compiler,but my project have to use antlr4)so I'm searching for help
I've been debugging this for hours already but really can't find the culprit of this illegal character. My javascript looks fine. This is my code.
this.PrintApplication = function Test$PrintApplication(ApplicationID, callback) {
$.post("/Application/PrintApplication/" + ApplicationID,
function (data) {
var result = eval(data);
if (result.error) {
DisplayPrompt("Error", result.message);
return;
}
else {
callback(result.data);
}
});
};
In firebug it shows.
In inspect in chrome and in console it redirects me in this line.
Any idea where is that illegal character is in my function?
It looks like you've got some unprintable characters in your source. Do you have a way of displaying those in your editor and deleting them? Deleting and retyping the line might fix it as well.
If that's not the case, maybe what you're trying to evaluate isn't JavaScript at all. You could be running that on an image or some kind of binary data.
Remember to be extra super careful when using eval on data that comes from an external source. If you can avoid doing it, avoid it.
This might be due to the reason that you have copied the code from web and simply pasted in your file. Try typing the same code to the file.
This error occurs due to UTF-8 characters.
This could happen if you normally type with different alphabets. For example the Γreek question mark ; is a different ASCII character from the English semi colon ;. If you use the first, you'll get exactly this error.
One solution is to copy paste your method to notepad and then back to your IDE.
This will often normalise and eliminate weird characters that might be hidden or undecipherable.
I wrote a test using selenium IDE, I need to compare two text that MAY contain the
character, if the strings are equal, it skips to a label. the comparison command
<td>gotoIf</td>
<td>'${var1}'=='${var2}'</td>
<td>skip</td>
works if the character above is not there, but fails with
[error] Threw an exception: missing ; before statement` otherwise
I tried to write a replace statement supposed to replace ' with a blank space (since I don't care if is there or not):
<td>storeEval</td>
<td>javascript{storedVars.var1.replace("\'"," ");}</td>
<td>var1</td>
but it always fails with the same error as above.
what am I missing? can anyone help me?
I took user extension js from here. Can you try with double quote instead of single quote in gotoIf command? It works for me. Please refer my screenshot below.
<td>gotoIf</td>
<td>"${var1}"=="${var2}"</td>
<td>skip</td>
I am having an issue checking in a minified JavaScript file into Clearcase. The file in question is a single line, well over the 8000 character limit that Clearcase imposes.
I know that JavaScript interpreters do some tricky things inserting semicolons at linebreaks, but I am wondering if it should always be safe to add a linebreak after a semicolon. Is it possible that doing so would change the meaning of the JavaScript code?
To answer your immediate question: yes, you can add line breaks after a semicolon that ends a statement. There may be other uses of semicolons (e.g. inside a string or regex) in the file, and you shouldn't touch those.
I have another question for you: Why are you checking in a minified JavaScript file? I would think it's better to check in the original verbose JavaScript source. Plus, version control systems aren't effective in general for files of only one line. If you are already checking in the original JavaScript, you now have to maintain consistency between the two files (i.e. when you change one you must refresh the other). I suggest checking in a script that will minify the original when you deploy it instead of keeping the minified version in Clearcase.
A semicolon might be encapsulated in a string. Adding a line break to the string would change the meaning of the javascript.
If the semicolon is inside of a string or a regex (such as var rex = /;/g; — it's only safe to insert a line break after the second semicolon), then yes, that would obviously be a problem. Otherwise, it's always safe to have a line break after a statement.
Admin or maybe developer needs to run this command on each VOB where artifact is stored
(in context of desired VOB)
(not 100% sure about the -supertype, "binary_file" might be better)
(not 100% sure about the -mergetype, "copy" might be better!)
(you can always change this later via -replace option)
cleartool mkeltype -nc -supertype text_file -manager z_whole_copy -mergetype auto text_file_minified
This can be used to correct files that failed trying to checkin.
They have probably been created with a type of "text_file"
individual lines of text_file types cannot exceed 8000 characters.
cleartool chtype -nc -force text_file_minified jquery-1.8.2.min.js
PUT this file on your desktop/dev machine where you checkin.
Remove any leading spaces.
# AAA.magic
# This needs to copied to all developer desktops
# copy it next to default.magic (or cc.magic)
# under ...\ClearCase\config\magic
# Leave these from the default.magic just in case
# files are processed in alphabetic order, hence the AAA prefix
# Check stat type
directory : -stat d ;
block_device : -stat b ;
char_device : -stat c ;
socket : -stat s ;
fifo : -stat f ;
# minified javascript and CSS
# some of these violate the 8000 character per line limit
# of clearcase text tools/type managers
# *.min.js
text_file_minified : -name "*.[mM][iI][nN].[jJ][sS]" ;
# *.min.css
text_file_minified : -name "*.[mM][iI][nN].[cS][sS][sS]" ;
A semi-colon in Javascript always determines the end of a code line.
Given this, it should always be safe to add a line break after a semi-colon unless that semi-colon is part of a string.