How to use "Adding Shared Settings" feature mentioned in the document of ESLint? - eslint

The official document mentions
ESLint supports adding shared settings into configuration files. Plugins use settings to specify information that should be shared across all of its rules. You can add settings object to ESLint configuration file and it will be supplied to every rule being executed.
and gives an example for writing a shared setting:
{
"settings": {
"sharedData": "Hello"
}
}
How can I use the shared settings for affecting rules? And how do the shared settings interect with the rules?

Related

Gatsby extend ESLint rules overwrites original ESLint

I am following the directions in the documentation https://www.gatsbyjs.org/docs/eslint/, and would like to overwite one of the rules, but not affect the others, what I did is create an .eslintrc.js file.
This is the content of the file
module.exports = {
globals: {
__PATH_PREFIX__: true,
},
extends: `react-app`,
"rules": {
'jsx-a11y/no-static-element-interactions': [
'error',
{
handlers: [
'onClick',
'onMouseDown',
'onMouseUp',
'onKeyPress',
'onKeyDown',
'onKeyUp',
],
},
],
}
}
but the rest of the rules are now ignored, like it was not an extension
While the answer above is correct, it is a bit incomplete. The thing is eslint can be integrated both in builds and editors.
When you start using a custom .eslintrc.js you will lose the integration on build and output in the terminal based on those rule. That's because the built-in eslint-loader is disabled when you use a custom file. It actually says so on the documentation page but it is a bit unclear.
To get that back, you will need to integrate it in the webpack build. The easiest way is using the plugin mentioned on the doc page: gatsby-plugin-eslint.
I filed an issue to make custom integrations easier.
From the Gatsby docs you linked to:
When you include a custom .eslintrc file, Gatsby gives you full control over the ESLint configuration. This means that it will override the built-in eslint-loader and you need to enable any and all rules yourself. One way to do this is to use the Community plugin gatsby-eslint-plugin. This also means that the default ESLint config Gatsby ships with will be entirely overwritten. If you would still like to take advantage of those rules, you’ll need to copy them to your local file.
So it looks like as soon as your create a .eslintrc.js file, you need to build your rules up from the bottom again. It overwrites, it doesn't extend.

Auto loading setting file depending on environment with Azure Functions 2.x and VS

I need to support multiple settings file for different environment, e.g. Dev, Prod, for Azure Functions.
Below is what I tried, I want to find out if it is possible to make the settings file loaded automicatlly without step 2, and 3, like ASP.NET CORE 2.x.
Step 1: The settings files below are defined,
MyAppSettings.development.json
{
ThirdParty: {
"Key": "Key1"
}
}
MyAppSettings.production.json
{
ThirdParty: {
"Key": "Key2"
}
}
Step 2: Define an environment variable that is used to load the settings file
Settings_File_To_Load: MyAppSettings.development.json
Is it possible to reuse a variable instead of creating a new one, e.g. ASPNETCORE_ENVIRONMENT
Step 3: Read the value of "Settings_File_To_Load", and load the content of the file.
Is it possible to let the file automicatlly loaded?
Again, is it possible to make the settings file loaded automicatlly without step 2, and 3?
Visual studio 2017
There is no automatic override for the settings file- the runtime is expecting local.settings.json and you must override this if you want to use multiple settings files in local development.
If you are changing the settings as part of publishing the solution to Azure, you can override the settings in the local.settings.json as part of the publish profile. You can use the slots feature in Azure Functions to allow for multiple configs/environments within the service.

Overriding ServiceStack Templates with Embedded Resources

Service stack documentation explains that templates for meta and operation pages may be overridden using static files.
https://github.com/ServiceStack/ServiceStack/wiki/Virtual-file-system
This works well, however, I would prefer to deploy all my resources as embedded resources.
My assumption was that by registering my EmbeddedResourceSources in the hostConfig, that they would take precedence over the existing service stack templates but that does not seem to be the case:
SetConfig(new HostConfig
{
EmbeddedResourceSources = {typeof(ApiUiResource).Assembly},
EmbeddedResourceBaseTypes = {typeof(ApiUiResource)},
});
The above works to serve all my other files, but the default pages for the meta and operations pages are still shown. Is what I am attempting to do possible?
The Config.EmbeddedResourceBaseTypes contains the order by which the embedded resource virtual files are loaded, so you'll need add yours at the start of the list to take precedence:
var config = new HostConfig
{
EmbeddedResourceSources = {typeof(ApiUiResource).Assembly},
};
config.EmbeddedResourceBaseTypes.Insert(0,typeof(ApiUiResource));
SetConfig(config);
An alternative solution is to override GetVirtualFileSources() in your AppHost to change the order which the virtual file sources are returned, see the docs for an example of this.

Can I set extension policies locally from the registry?

I have a Chrome Extension and I added a managed_schema to define a property (SomeSetting) so I can set it via a policy.
manifest.json:
"storage": { "managed_schema": "schema.json" }
schema.json:
"properties": { "SomeSetting": { "type": "string" } }
I can see SomeSetting in chrome://policy/ but I have no idea how to set the value. Apparently I can do this at HKLM\SOFTWARE\Policies\Google\Chrome\3rdparty\extensions... but I tried and it never is shown as set in chrome://policy/.
Does anyone know if this is suppose to work? Does it have to be HKCU instead? Or do I need Active Directory because setting values locally via the registry is not supported?
I had a hard time figuring this out. The documentation is not all that clear.
In order to get your schema to work you need to add a registry entry for "SomeSetting".
Go to the following item in your registry (create the necessary items):
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\3rdparty\extensions\aaaaaaaaaaaaaa\policy
where aaaaaaaaaaaaaa is your extension ID from chrome://extensions
Right-click on "policy" and create a new string value:
Name: SomeSetting
Data: "some value"
Go back to Chrome and reload chrome://policy/
The new policy should appear.
From your extension, you can access the value like this:
chrome.storage.managed.get("SomeSetting", function(setting_val) {
console.debug(setting_val);
});
I'm not sure if this requires Active Directory to work.
It was mentioned in Alternative Extension Distribution Options that:
Google Chrome supports the following extension installation methods:
Using a preferences JSON file (for Mac OS X and Linux only)
Using the Windows registry (for Windows only)
More information regarding other mechanisms on extensions distribution options can be found in the documentation.

How to use Restrict attribute in service stack

Is there any documentation on use of [Restrict] attribute with service stack?
Not finding any documentation, I started trying to figure this out. I discovered you have to enable restrictions in AppHost.cs Configure event with
var endpointHostConfig = new EndpointHostConfig
{
EnableAccessRestrictions = true,
};
Then I added attributes to my request DTO:
[Route("Hello/World", "GET")]
[Restrict(EndpointAttributes.InternalNetworkAccess)]
This does not work...looks like that removes all 'default' restrictions and replaces it with just that one restriction? Using this instead seems to work:
[Restrict(InternalOnly = true)]
When I do a GET from the local lan it works, but from remote it does not. Interesting, the 'detailed stack error' it gives from remote is:
The following restrictions were not met: '\n -[InternalNetworkAccess, Secure, HttpHead, HttpPost, HttpPut, HttpDelete,
HttpOther, OneWay, Soap11, Soap12, Xml, Jsv, ProtoBuf, Csv, Html, Yaml, MsgPack, FormatOther, AnyEndpoint]'
Note, it does not even list HttpGet as one of the possiblities - which does work. Also mentions Secure and not InSecure...neither of which I am specifically requiring.
Can we get some clarification on exactly how this is supposed to work? What if I wanted to require SSL - how would I specify that?
What if I wanted to require SSL in production, but not staging on all services for this endpoint? (Realizing this may be a completely different way to configure).
The [Restrict] attribute feature is in the latest version of ServiceStack. Currently the only documentation for this exists in the Security wiki page.
Here are some EndpointAttributes restrictions tests that test the validation of the restriction attributes, and some different service configurations you can use.
The way it works is that it's restricted to anything that's specified, so if you want to enable SSL and leave everything else as unrestricted, you would only add:
[Restrict(EndpointAttributes.Secure)]
public class SslOnly { }
It also supports specifying multiple combinations of environments that are allowed, e.g. You can enforce HTTP internally, but HTTPS externally with:
[Restrict(EndpointAttributes.Secure | EndpointAttributes.External,
EndpointAttributes.InSecure | EndpointAttributes.InternalNetworkAccess)]
public class SslExternalAndInsecureInternal { }
Note: each environment is combined with Enum flags and delimited with a ,.
But it doesn't let you distinguish between debug and release builds, to enable this you would need to use C# conditional compilation symbols.
E.g only allow HTTP for Debug builds and HTTPS for production Release builds:
#if DEBUG
[Restrict(EndpointAttributes.InSecure)]
#else
[Restrict(EndpointAttributes.Secure)]
#endif
public class MyRequestDto { ... }

Resources