Skip to content

Commit

Permalink
Merge e0aa9d8 into e26d2e5
Browse files Browse the repository at this point in the history
  • Loading branch information
kristerkari committed Oct 18, 2018
2 parents e26d2e5 + e0aa9d8 commit 0034b40
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ $ npm install stylelint

* `browsers`: optional. Accepts an array of browsers you want to support. For example `['> 1%', 'Last 2 versions']`. See [browserslist](https://github.com/ai/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. A boolean to turn off warnings for partially supported features.

So for example, in a `.stylelintrc`:

Expand All @@ -49,7 +50,8 @@ So for example, in a `.stylelintrc`:
"rules": {
"plugin/no-unsupported-browser-features": [true, {
"browsers": ["> 1%", "Last 2 versions"],
"ignore": ["rem"]
"ignore": ["rem"],
"ignorePartialSupport": true
}]
}
}
Expand Down
27 changes: 27 additions & 0 deletions lib/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ Object {
}
`;

exports[`stylelint-no-unsupported-browser-features ignorePartialSupport option should not warn for flex when ignoring partially supported features 1`] = `
Object {
"deprecations": Array [],
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [],
}
`;

exports[`stylelint-no-unsupported-browser-features ignorePartialSupport option should warn for flex without ignoring partially supported features 1`] = `
Object {
"deprecations": Array [],
"errored": true,
"invalidOptionWarnings": Array [],
"parseErrors": Array [],
"warnings": Array [
Object {
"column": 7,
"line": 1,
"rule": "plugin/no-unsupported-browser-features",
"severity": "error",
"text": "Unexpected browser feature \\"flexbox\\" is only partially supported by IE 11 (plugin/no-unsupported-browser-features)",
},
],
}
`;

exports[`stylelint-no-unsupported-browser-features multiple browsers should allow display:table for IE 8 and IE 9 1`] = `
Object {
"deprecations": Array [],
Expand Down
18 changes: 17 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ const messages = stylelint.utils.ruleMessages(ruleName, {

const optionsSchema = {
browsers: [_.isString],
ignore: [_.isString]
ignore: [_.isString],
ignorePartialSupport: [_.isBoolean]
};

/**
* Regular expressions
*/

const isPartiallySupportedRE = /only partially supported by/;
const isNotSupportedRE = /not supported by/;

/**
* Utilities
*/
Expand Down Expand Up @@ -65,6 +73,14 @@ function ruleFunction(on, options) {

doiuse(doiuseOptions).postcss(root, doiuseResult);
doiuseResult.warnings().forEach(doiuseWarning => {
if (
options.ignorePartialSupport &&
isPartiallySupportedRE.test(doiuseWarning.text) &&
isNotSupportedRE.test(doiuseWarning.text) === false
) {
return;
}

stylelint.utils.report({
ruleName,
result,
Expand Down
46 changes: 46 additions & 0 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,52 @@ describe('stylelint-no-unsupported-browser-features', () => {
});
});

describe('ignorePartialSupport option', () => {
it('should warn for flex without ignoring partially supported features', done => {
const code = 'div { display: flex; }';
const rules = {
'plugin/no-unsupported-browser-features': [
true,
{
browsers: ['IE 11']
}
]
};
const options = getOptions(code, rules);

return stylelint
.lint(options)
.then(result => {
expect(result.errored).toBe(true);
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(error => done(error));
});
it('should not warn for flex when ignoring partially supported features', done => {
const code = 'div { display: flex; }';
const rules = {
'plugin/no-unsupported-browser-features': [
true,
{
browsers: ['IE 11'],
ignorePartialSupport: true
}
]
};
const options = getOptions(code, rules);

return stylelint
.lint(options)
.then(result => {
expect(result.errored).toBe(false);
expect(parseResult(result.output)).toMatchSnapshot();
return done();
})
.catch(error => done(error));
});
});

describe('validate options', () => {
it('should validate the browsers option', done => {
const code = '';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"eslint-plugin-import": "^2.13.0",
"husky": "^0.14.3",
"jest": "^23.4.1",
"jest-cli": "^23.6.0",
"key-del": "^1.3.0",
"lint-staged": "^7.0.0",
"prettier": "^1.13.2",
Expand Down

0 comments on commit 0034b40

Please sign in to comment.