How do you turn off the ESLint no-undef rule in VS Code settings, but only for certain variables? - eslint

I know it's possible to completely turn off the 'no-undef' rule in VS Code's settings.json using something like:
{
"eslint.rules.customizations": [
{ "rule": "no-undef", "severity": "off" }
]
}
What I'd like to do is turn it off in settings ONLY for a handful of specific global variables that are used in most of the 400+ JS files in our codebase. I'd really like to be able to do it without having to add header comments to every file I work with, which is why I'd prefer to do it in the settings.
I did some searching online for how to configure ESLint rules but didn't see anything that addressed this (for that matter, I didn't find anything that would have taught me the method above that turns it off completely; I learned that from another developer).

Related

Disable specific Pylance linting messages in VS Code settings.json like with "python.linting.pylintArgs"

When Pylance was introduced, I filed a question on how to generally customize Pylance linting. Here, one can find a few ways to customize Pylance, but there is nothing about how to suppress, mute or actually disable certain warnings and errors.
As a recap, with pylint one can specify the following in VS Code settings.json to disable a certain error/warning:
"python.linting.pylintArgs": [
"--disable=C0111"
]
As for the background, since the excessive Pylance(reportMissingImports) linting errors has not been resolved yet and due to project requirements, I've enabled pylint simultaneously with Pylance. Still, these countless Pylance(reportMissingImports) linting errors are annoying and I'd like to silence them completely.
Find the error-message you want to modify/disable in the Pylance's Diagnostic Severity Rules (in my case "reportMissingImports")
Modify settings.json with "reportMissingImports": "none" (see diagnosis reporting levels in Pylance's Settings and Customization)
The entire JSON-code to be inserted into the settings.json is:
"python.analysis.diagnosticSeverityOverrides": {
"reportMissingImports": "none"
}
As an aside, if you want to be at least informed about unused imports, you can use:
"python.analysis.diagnosticSeverityOverrides": {
"reportUnusedImport": "information",
"reportMissingImports": "none"
}
PS: regarding the settings.json - location
Along with the global settings.json there are also local versions in your VS-Code-projects' parent directories. In the following, example paths are provided based on my Windows 10 - OS:
global: C:\Users\user.name\AppData\Roaming\Code\User\settings.json
local: .vscode/settings.json
These local project settings override the global ones, if desired.

opensnitch: changing a "process.path" rule to match command args

Opensnitch intro
opensnitch is an open-source security tool modeled after the MAC OS-X littlesnitch app.
I've been using Gustavo Iniguez Goya's fork of opensnitch (which is a big improvement over the original great pioneering work by Simone Margaritelli) on my desktop to limit outgoing connections based on rules. The goal is to beef-up outgoing network security, for example to catch malware or limit some "phone-home" apps from talking to the outside world.
Configuration/rules
The default rules which drive opensnitch, are created under /etc/opensnitchd/rules are stored as *.json files, one file per rule. When I use the UI to add a rule, a new *.json rule file gets created.
Example of a rule (trimmed down for brevity):
{
"name": "allow-always-simple-usrbinpython",
"enabled": true,
"action": "allow",
"duration": "always",
"operator": {
"type": "simple",
"operand": "process.path",
"data": "/usr/bin/python",
}
}
Problem
These rules may be too coarse when setting them from the UI. e.g. when I allow a certain script I wrote to talk to the outside world, and that executable just happens to be written in python selecting the executable option and clicking Allow, I inadvertently allow any python script to talk to the outside world.
Searching the web, I was able to find a nice overview of opensnich which is missing the detail of how to specify conjunctive rules directly in *.json and match the full command line, with examples.
Questions:
Is it possible to limit such rule and allow running only a certain executable script (1st arg to /usr/bin/python) ?
More generally: what would be the syntax, with an example, for an AND conjunction in the rule, and a clause for a regex-match vs. other arguments of the command line or remote IP-addresses, or both?
Is it possible to limit such rule and allow running only a certain executable script (1st arg to /usr/bin/python) ?
You can select the option "from this command line" to filter by the whole command.
More generally: what would be the syntax, with an example, for an AND conjunction in the rule, and a clause for a regex-match vs. other arguments of the command line or remote IP-addresses, or both?
take a look at the documentation (maybe you already did... but just in case):
https://github.com/gustavo-iniguez-goya/opensnitch/wiki/Rules
https://github.com/gustavo-iniguez-goya/opensnitch/wiki/Rules-editor
For example, if you wanted to filter by a particular (python) script:
[x] From this command line: ".*/usr/bin/dnsping.*"
(By the way, we finally are contributing to the original repo, so you can use latest releases from there)

Double Filetype Extension: Correct Syntax Highlighting in Sublime Text 3

I am working with some .scss.liquid files and they always open as HTML Liquid, no matter how many times I set the syntax.
Update:
I tried open all with current extension as option, but unfortunately this affects files that are .js.liquid and .html.liquid as well.
Sublime Text allows you to apply settings on a per-language basis (actually, per syntax). One of the available settings allows you to map file extensions to the given syntax.
Assuming you're using a syntax named SCSS, Create an SCSS settings file in your User settings: /path/to/packages/User/SCSS.sublime-settings, then add the file extension setting:
{
"extensions":
[
"scss.liquid"
]
}
As you can see, it's a json file, and extensions is a list, so you can add as many file extensions as you need. Do not add the leading dot.
Caveat about the file name
The file name for the settings file must match the actual syntax name, including case. In this case it has to be SCSS.sublime-settings. Other examples include:
NAnt Build File.sublime-settings
Ruby on Rails.sublime-settings
Rd (R Documentation).sublime-settings
Java Server Page (JSP).sublime-settings
I found a relatively straightforward solution to this problem.
Install ApplySyntax
Create the following rules in ApplySyntax.sublime-settings -- User:
"syntaxes": [
{
"syntax": "SCSS",
"extensions": ["scss.liquid"]
},
{
"syntax": "JavaScript/JavaScript",
"extensions": ["js.liquid"]
},
]
Update: I now see there is no need for an extra package. Please see accepted answer and my video (in the comments) for tips on how to make it work.

Use node `fs` module on webpack compile

A bit about what I'm trying to achieve.
I'm building dev library that shows the list of files. And I want to set file color depending on when file was changed.
So, as a result of generation, I want an array like this:
[
{
lastChange: '2009-06-29T11:11:55Z',
fileContents: {name: 'VmSome'},
},
// ...
]
This is meant to work in browser environment. Meaning all file related information should be included into bundle.
Current progress
At the moment I'm not quite sure whether that's even possible.
I'm getting a list of files via webpack require.context:
require.context('./tree', true, /.js$/)
This gives me access to file content and path. But not to anything else.
Thanks for your attention.
I would first try modifying webpack-file-list-plugin. As of now, it creates a JSON that gives all files packed, their name and some more info... You could definitely add your code to fetch more information to the JSON.
https://github.com/object88/webpack-file-list-plugin/blob/master/src/index.js

Chrome extension, Grunt+Bower (from yeoman template) won't load plugins

I just though I make my life easier by sticking to common structures, so I started transferring a chrome browser extension to a yeoman template format
(https://github.com/yeoman/generator-chrome-extension).
Unfortunately it simply does not work when I try to just add my first basic bower source that I need:
https://github.com/Yaffle/EventSource
Here is what I did:
Set up the new extension with the yeoman helper
$ bower install EventSource --save
Added event source to the manifest like so
"background": {
"scripts": [
"scripts/chromereload.js",
"app/bower_components/EventSource/eventsource.js",
...
Add "new EventSource('http://localhost:9292/updates');" to background.js
Other than that the project is untouched.
And whenever I start the project with grunt it fails not finding EventSource like so "'EventSource' is not defined."
Adding the eventsource.js directly to my script folder and require it from there fails even worse by linting the eventsource.js file (that works perfectly fine) and aborting it for too many warnings (like using single quotes).
Previously this whole project worked pretty fine without grunt/bower and now it won't even start after I added the first real line of code. This is quite disappointing for a tool that is supposed to make your life so much easier.
Does it fail because of the warnings in the eventsource.js? In the first case (via bower) it does not say anything about this so I'm not sure.
I could go on trying out different combinations but I'm obviously missing a core concept or something like this here.
Any idea?
Update:
After some more trying and giving up i found the magic "grunt bowerInstall" command, to add the script-tags in the template automatically - still no help.
I did also try again on a fresh project with just jQuery (assuming this has to work..), well it still does not.
Neither in the popup.js (where the html template includes jQuery) nor in the background script (where the manifest includes it).
I probably read every manual/how-to on hot to use either of those components and still get nowhere.
Another day another try:
Starting with a clean mind i looked a bit more into it today finding out that apparently you have to "whitelist" globals like $ in jshint like so:
http://jshint.com/docs/options/#jquery
Still not sure if this is actually the best approach as it seems very counter-intuitive with promised ease of getting started of the yeoman/grunt/bower framework.
EventSource is probably a global variable. You can try declaring it as false in the .jshintrc file to prevent it from being overwritten.
"globals" : {
"chrome": true,
"crypto": true,
"EventSource": false
}
See if that works.
Read more about .jshintrc + global variables at: JSHint and jQuery: '$' is not defined

Resources