-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebbb437
commit b3b5cfe
Showing
12 changed files
with
1,394 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sumup/foundry': minor | ||
--- | ||
|
||
Added support for linting CSS files with [Stylelint](https://stylelint.io/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* Copyright 2023, SumUp Ltd. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { customizeConfig, createConfig } from './config'; | ||
|
||
describe('stylelint', () => { | ||
describe('customizeConfig', () => { | ||
it('should merge the presets of the base config with the custom config', () => { | ||
const baseConfig = { | ||
extends: ['some-preset'], | ||
rules: { | ||
'some-custom-rule': false, | ||
}, | ||
}; | ||
const newConfig = { | ||
extends: ['other-preset'], | ||
}; | ||
const actual = customizeConfig(baseConfig, newConfig); | ||
expect(actual).toEqual( | ||
expect.objectContaining({ | ||
extends: ['some-preset', 'other-preset'], | ||
rules: { | ||
'some-custom-rule': false, | ||
}, | ||
}), | ||
); | ||
}); | ||
|
||
it('should merge the extends of the base config with the custom config', () => { | ||
const base = { | ||
extends: ['airbnb-base', 'plugin:prettier/recommended'], | ||
}; | ||
const custom = { | ||
extends: ['plugin:react/recommended'], | ||
}; | ||
const expected = { | ||
extends: [ | ||
'airbnb-base', | ||
'plugin:prettier/recommended', | ||
'plugin:react/recommended', | ||
], | ||
}; | ||
const actual = customizeConfig(base, custom); | ||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('should merge the rules of the base config with the custom config', () => { | ||
const base = { | ||
rules: { | ||
'no-use-before-define': ['error', { functions: false }], | ||
'curly': ['error', 'all'], | ||
'no-underscore-dangle': [ | ||
'error', | ||
{ allow: ['__DEV__', '__PRODUCTION__'] }, | ||
], | ||
}, | ||
}; | ||
const custom = { | ||
rules: { | ||
'react-hooks/rules-of-hooks': 'error', | ||
'react-hooks/exhaustive-deps': 'warn', | ||
'no-underscore-dangle': ['warning', { allow: ['__resourcePath'] }], | ||
}, | ||
}; | ||
const expected = { | ||
rules: { | ||
'no-use-before-define': ['error', { functions: false }], | ||
'curly': ['error', 'all'], | ||
'no-underscore-dangle': ['warning', { allow: ['__resourcePath'] }], | ||
'react-hooks/rules-of-hooks': 'error', | ||
'react-hooks/exhaustive-deps': 'warn', | ||
}, | ||
}; | ||
const actual = customizeConfig(base, custom); | ||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('with overrides', () => { | ||
it('should merge with the default config', () => { | ||
const overrides = { | ||
extends: ['stylelint-config-styled-components'], | ||
}; | ||
const actual = createConfig(overrides); | ||
expect(actual).toEqual( | ||
expect.objectContaining({ | ||
extends: expect.arrayContaining([ | ||
'stylelint-config-standard', | ||
'stylelint-config-styled-components', | ||
]), | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* Copyright 2023, SumUp Ltd. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Config as StylelintConfig } from 'stylelint'; | ||
import { mergeWith, isArray, isObject, uniq } from 'lodash/fp'; | ||
|
||
export const customizeConfig = mergeWith(customizer); | ||
|
||
function isArrayTypeGuard(array: unknown): array is unknown[] { | ||
return isArray(array); | ||
} | ||
|
||
function customizer( | ||
objValue: unknown, | ||
srcValue: unknown, | ||
key: string, | ||
): unknown { | ||
if (isArrayTypeGuard(objValue) && isArrayTypeGuard(srcValue)) { | ||
return uniq([...objValue, ...srcValue]); | ||
} | ||
if (isObject(objValue) && isObject(srcValue)) { | ||
return key === 'rules' ? { ...objValue, ...srcValue } : undefined; | ||
} | ||
return undefined; | ||
} | ||
|
||
const base: StylelintConfig = { | ||
extends: ['stylelint-config-standard', 'stylelint-config-recess-order'], | ||
plugins: ['stylelint-no-unsupported-browser-features'], | ||
rules: { | ||
'declaration-block-no-redundant-longhand-properties': null, | ||
'media-feature-range-notation': ['prefix'], | ||
'no-descending-specificity': null, | ||
'selector-class-pattern': null, | ||
'selector-not-notation': ['simple'], | ||
'selector-pseudo-class-no-unknown': [ | ||
true, | ||
{ ignorePseudoClasses: ['global'] }, | ||
], | ||
'value-keyword-case': ['lower', { camelCaseSvgKeywords: true }], | ||
'plugin/no-unsupported-browser-features': [ | ||
true, | ||
{ severity: 'warning', ignorePartialSupport: true }, | ||
], | ||
}, | ||
reportDescriptionlessDisables: true, | ||
reportInvalidScopeDisables: true, | ||
reportNeedlessDisables: true, | ||
}; | ||
|
||
export function createConfig(overrides: StylelintConfig = {}): StylelintConfig { | ||
return customizeConfig(base, overrides); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright 2023, SumUp Ltd. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import dedent from 'dedent'; | ||
|
||
import { Script, File } from '../../types/shared'; | ||
|
||
export const files = (): File[] => [ | ||
{ | ||
name: '.stylelintrc.js', | ||
content: ` | ||
module.exports = require('@sumup/foundry/stylelint')()`, | ||
}, | ||
{ | ||
name: '.stylelintignore', | ||
content: `${dedent` | ||
node_modules/ | ||
build/ | ||
dist/ | ||
.next/ | ||
.out/ | ||
static/ | ||
public/ | ||
coverage/ | ||
__coverage__/ | ||
__reports__/ | ||
`}\n`, | ||
}, | ||
]; | ||
|
||
export const scripts = (): Script[] => [ | ||
{ | ||
name: 'lint:css', | ||
command: "foundry run stylelint '**/*.css'", | ||
description: 'check files for problematic patterns and report them', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright 2023, SumUp Ltd. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { createConfig } from './configs/stylelint/config'; | ||
|
||
export = createConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters