Eslint & SAPUI5: How to remove "sap/$ not defined"? - sapui5

I am using Eslint in Visual Code for my SAPUI5 project. Whenever I am defining a controller using
sap.ui.define([...
Eslint throws the error sap not defined.. The same holds for $/jQuery. Is there a way how to solve that?
Thanks

You can whitelist global variables in the eslint configuration: https://eslint.org/docs/user-guide/configuring (see "Specifying Globals").
To configure global variables inside of a configuration file, use the
globals key and indicate the global variables you want to use. Set
each global variable name equal to true to allow the variable to be
overwritten or false to disallow overwriting. For example:
{
"globals": {
"var1": true,
"var2": false
}
}
Usually you have some kind of .eslintrc.js file where you can include this.
Here is an example: https://github.com/pulseshift/openui5-gulp-starter-kit/blob/master/.eslintrc.js

Related

Prevent Flutter/Dart format reordering variable declarations

Is there a way to prevent the dart formatter from reordering variables alphabetically? I can't find a linting rule for it although there's the similar directives_ordering for imports.
For example
var variableA; //A
var variableC; //C
var variableB; //B
gets reordered to
var variableA; //A
var variableB; //C
var variableC; //B
leaving comments in place.
This is especially problematic when I group constants together with a similar purpose and they get split up/mixed with other different constants making the accompanying comments useless/confusing.
I'm using Flutter 2.5.0 on VSCode 1.60.0 with include: package:flutter_lints/flutter.yaml in my analysis_options.yaml file.
Thanks for your help
For me it turns out this was due to the dart plugin for VSCode. Specifically the source.sortMembers value in the editor.codeActionsOnSave of my VSCode configuration file.
Setting this to false stops the variables being reordered.
The same behavior happens if you press CTRL + Shift + P and run Dart: Sort Members.
Apply it for the entire project
Open your analysis_options.yaml file
add this line to it
directives_ordering: false
Complete code
include: package:flutter_lints/flutter.yaml
linter:
rules:
# avoid_print: true # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
directives_ordering: false

Azure devops custom extension output variables

I am trying to create an extension using node api which publishes a path variable on completion.
I did set outputVariables in task.json and tried to use both
tl.setVariable('outVar1', 'outVal1'))
tl.setTaskVariable('outVar1', 'outVal1'))
task.json (only outvariable section):
"OutputVariables": [
{
"name": "outVar1",
"description": "This publish a output variable."
}
],
I tried printing it in the subsequent steps in the same job using all the recomended constructs
$(taskName.outVar1)
$taskName.outVar1
$outVar1
$(outVar1)
But the variable is not visible. I also printed all the environment variables and the variable is not present there.
Is someone able to create an extension which outputs a variable successfully?
You don't need to declare an output variable fro this purpose.
Just set the variable:
tl.setVariable("varNamr","varValue", false);
The fasle indicate that is not a secret variable.
In the enxt steps you can use the variable wirh $(varName).

Disable default settings like "wordBasedSuggestions" from an Extension

I'm developing an extension for VSCode which is supplying completion items but there are word suggestions among them.
I know you can in your User/Workspace settings disable editor.wordBasedSuggestions but are there a way to this from an extension?
Yes, extensions can change the default value of settings by contributing configurationDefaults in package.json:
"contributes": {
"configurationDefaults": {
"[lang]": {
"editor.wordBasedSuggestions": false
}
}
}
Where lang is the ID of the language in question.
This can now be done in a general non-language-specific method. See release notes: change configuration defaults.
Configuration Defaults Overrides
You can now override defaults of other registered configurations
through configurationDefaults contribution point in package.json.
For example, the following snippet overrides the default behavior of
files.autoSave setting to auto save files on focus change.
"contributes": {
"configurationDefaults": { // applies to all languages
"files.autoSave": "onFocusChange"
}
}
Note: Configurations with application or machine scopes cannot be
overridden.

How to dictate a global variable in specific karma test block

I'm trying to write a test in Karma for a react/webpack application that tests conditionals depending on global variable __CLIENT__ being false or not.
How do I go about making it true for one it block, and then false for another? I tried setting global.__CLIENT__, but the console.logs from my module return true regardless of what I try to set it to in my tests.
How do I do this, hopefully in a way that keeps just one file and can be dictated in each test case. That avoids the karma.conf....
Probably won't help you now but maybe for others:
you need to create global.js file for example and within karma webpack files add it at the start of "files"
files: [
'./tests/global-variables.js',
{pattern: 'src/**/*-spec.js', watch: false}
],
And within global-variables.js:
var global = {
___CLIENT___: "some data"
}
Good luck!

Setting the --in-source-map uglify2 config option in r.js build config file

I wanted to use the --in-source-map option that is available in UglifyJS2 for consuming a source map file and outputting a new one along with the compressed js, thereby performing a multi-level source mapping. I am using r.js to do the minification of the javascript files and so I saw there was a way to define config values that will be passed on to the UglifyJS2. Here is a sample showing how it is done in the r.js build file:
uglify2: {
//Example of a specialized config. If you are fine
//with the default options, no need to specify
//any of these properties.
output: {
beautify: true
},
compress: {
sequences: false,
global_defs: {
DEBUG: false
}
},
warnings: true,
mangle: false
},
Obvously r.js has its own way of structuring the config options and I was not able to figure out how to set the --in-source-map option following this structure. I tried putting the following statement in the output element or the compress element or even outside, next to the warnings config option.
in-source-map: sample.map
I have also tried putting quotes around the file name. Unfortunately none of the methods worked. Can anyone help me figure out this problem? Can it also be the case that this option is not supported in r.js?