Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
stylelint-no-unsupported-browser-features
Advanced tools
Disallow features that are unsupported by the browsers that you are targeting
The stylelint-no-unsupported-browser-features package is a plugin for Stylelint that helps developers avoid using CSS features that are not supported by the browsers they are targeting. It leverages the data from caniuse.com to provide warnings or errors when unsupported features are detected in the CSS code.
Detect unsupported CSS features
This feature allows you to configure the plugin to detect unsupported CSS features based on the specified browser targets. The configuration in the code sample sets the plugin to warn about unsupported features for browsers with more than 1% market share, the last two versions of all browsers, and Firefox ESR.
module.exports = {
plugins: [
'stylelint-no-unsupported-browser-features'
],
rules: {
'plugin/no-unsupported-browser-features': [true, {
browsers: ['> 1%', 'last 2 versions', 'Firefox ESR'],
severity: 'warning'
}]
}
};
Customizing the severity of warnings
This feature allows you to customize the severity of the warnings or errors generated by the plugin. In this example, the severity is set to 'error', which will cause the build to fail if unsupported features are detected.
module.exports = {
plugins: [
'stylelint-no-unsupported-browser-features'
],
rules: {
'plugin/no-unsupported-browser-features': [true, {
browsers: ['> 1%', 'last 2 versions'],
severity: 'error'
}]
}
};
Ignoring specific features
This feature allows you to ignore specific CSS features that you do not want the plugin to check for. In this example, the plugin is configured to ignore warnings for CSS Grid and CSS Variables.
module.exports = {
plugins: [
'stylelint-no-unsupported-browser-features'
],
rules: {
'plugin/no-unsupported-browser-features': [true, {
browsers: ['> 1%', 'last 2 versions'],
ignore: ['css-grid', 'css-variables']
}]
}
};
Doiuse is a tool that checks your CSS against browser support data from caniuse.com. It provides warnings for unsupported features based on the specified browser targets. Unlike stylelint-no-unsupported-browser-features, doiuse is a standalone tool and not a Stylelint plugin, but it can be integrated into build processes similarly.
Autoprefixer is a PostCSS plugin that automatically adds vendor prefixes to CSS rules based on the specified browser support. While it does not warn about unsupported features, it helps ensure that your CSS works across different browsers by adding necessary prefixes. It complements stylelint-no-unsupported-browser-features by addressing a different aspect of cross-browser compatibility.
disallow features that aren't supported by your target browser audience
This plugin checks if the CSS you're using is supported by the browsers you're targeting. It uses doiuse to detect browser support. Doiuse itself checks your code against the caniuse database and uses browserslist to get the list of browsers you want to support. Doiuse and this plugin are only compatible with standard css syntax, so syntaxes like scss
, less
and others aren't supported.
$ npm install stylelint-no-unsupported-browser-features
Stylelint is a peerdependency of this plugin, so you'll have to install stylelint as well:
$ npm install stylelint
"stylelint-no-unsupported-browser-features"
to your stylelint config plugins array"plugin/no-unsupported-browser-features"
to your stylelint config rulestrue
, or pass optional extra configurationbrowsers
: optional. Accepts an array of browsers you want to support. For example ['> 1%', 'Last 2 versions']
. See browserslist for documentation.ignore
: optional. Accepts an array of features to ignore. For example: ['rem', 'css-table']
. Feature names can be found in the error messages.ignorePartialSupport
: optional, off by default. Accepts a boolean. When enabled:
So for example, in a .stylelintrc
:
{
"plugins": [
"stylelint-no-unsupported-browser-features"
],
"rules": {
"plugin/no-unsupported-browser-features": [true, {
"browsers": ["> 1%", "Last 2 versions"],
"ignore": ["rem"],
"ignorePartialSupport": true
}]
}
}
This is a good rule to use with "warning"-level severity, because its primary purpose is to warn you that you are using features not all browsers fully support and therefore ought to provide fallbacks. But the warning will continue even if you have a fallback in place (it doesn't know); so you probably do not want this rule to break your build. Instead, consider it a friendly reminder to double-check certain spots for fallbacks.
Also, doiuse uses browserslist to get the list of browsers you want to support. Browserslist accepts a browserslist
file at the root of your project with a list of browsers that you want to support. Since there are other projects that can use this file (like autoprefixer or eslint-plugin-compat) the simplest solution is to define your intended browser support in this file. There are a lot of different ways to define this list. Check out the browserslist documentation for more options.
For the above setup you could use the following config:
./.stylelintrc
{
"plugins": [
"stylelint-no-unsupported-browser-features"
],
"rules": {
"plugin/no-unsupported-browser-features": [true, {
"severity": "warning"
}]
}
}
./browserslist
:
> 5%
Last 2 versions
browsers
property within the rules section of .stylelintrc
you can ignore this issue. Changes to the browsers
property are discovered immediately.MIT
FAQs
Disallow features that are unsupported by the browsers that you are targeting
We found that stylelint-no-unsupported-browser-features demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.