-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add stylelint * feat: add use-logical stylelint rule * ci: update node versions to 20 * chore: remove executable bit * feat: add remaining config files * fix: remove unnecessary config file * fix: use base as default stylelint cfg * fix: add css type * fix: update for css type * fix: accept files and fix flag * style: fix js * fix: add default d2-style config * fix: add css as autofixable type * docs: add stylelint to readme
- Loading branch information
ismay
authored
May 15, 2024
1 parent
85e5abc
commit 4a8c70b
Showing
19 changed files
with
555 additions
and
14 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
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
Empty file.
Empty file.
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ module.exports = { | |
}, | ||
patterns: { | ||
js: '*.{js,jsx,ts,tsx}', | ||
css: '*.css', | ||
text: '*.{md,json,yml,html}', | ||
}, | ||
} |
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,11 @@ | ||
module.exports = { | ||
plugins: ['stylelint-use-logical'], | ||
rules: { | ||
'csstools/use-logical': [ | ||
true, | ||
{ | ||
severity: 'warning', | ||
}, | ||
], | ||
}, | ||
} |
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,34 @@ | ||
const log = require('@dhis2/cli-helpers-engine').reporter | ||
const cfg = require('../../utils/config.js') | ||
|
||
exports.command = 'stylelint [type]' | ||
|
||
exports.desc = 'Add Stylelint configuration to the project.' | ||
|
||
exports.builder = (yargs) => | ||
yargs | ||
.positional('type', { | ||
describe: 'Configuration template for Stylelint.', | ||
type: 'string', | ||
default: 'base', | ||
}) | ||
.option('overwrite', { | ||
describe: 'Overwrite the existing configuration.', | ||
type: 'boolean', | ||
}) | ||
|
||
exports.handler = (argv) => { | ||
const { add, type, overwrite } = argv | ||
|
||
log.info(`stylelint > ${add ? 'add' : 'remove'}`) | ||
|
||
if (add) { | ||
cfg.add({ | ||
tool: 'stylelint', | ||
type: type ? type : 'base', | ||
overwrite, | ||
}) | ||
} else { | ||
cfg.remove({ tool: 'stylelint', type: type ? type : 'base' }) | ||
} | ||
} |
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,85 @@ | ||
const log = require('@dhis2/cli-helpers-engine').reporter | ||
const { callback: runCb } = require('@dhis2/cli-helpers-engine').exec | ||
const { exit } = require('@dhis2/cli-helpers-engine') | ||
const { prettier } = require('../../tools/prettier.js') | ||
const { stylelint } = require('../../tools/stylelint.js') | ||
const { configured } = require('../../utils/config.js') | ||
const { selectFiles } = require('../../utils/files.js') | ||
const { | ||
sayFilesChecked, | ||
sayNoFiles, | ||
} = require('../../utils/std-log-messages.js') | ||
|
||
exports.command = 'css [files..]' | ||
|
||
exports.aliases = ['css'] | ||
|
||
exports.desc = 'CSS code style' | ||
|
||
exports.builder = (yargs) => | ||
yargs.positional('files', { | ||
describe: '', | ||
type: 'string', | ||
}) | ||
|
||
exports.handler = (argv, callback) => { | ||
if ( | ||
!argv.config.patterns || | ||
(argv.config.patterns && !argv.config.patterns.css) | ||
) { | ||
log.warn('No css patterns defined, please check the configuration file') | ||
exit(1) | ||
} | ||
|
||
const finalStatus = callback || runCb() | ||
|
||
const { | ||
config: { | ||
patterns: { css: cssPattern }, | ||
}, | ||
files, | ||
staged, | ||
apply, | ||
} = argv | ||
|
||
const cssFiles = selectFiles(files, cssPattern, staged) | ||
|
||
if (cssFiles.length === 0) { | ||
log.debug(sayNoFiles('css', cssPattern, staged)) | ||
return | ||
} | ||
|
||
if (configured('stylelint')) { | ||
log.info('css > stylelint') | ||
stylelint({ | ||
apply, | ||
files: cssFiles, | ||
callback: finalStatus, | ||
}) | ||
|
||
if (finalStatus() === 0) { | ||
log.print('All matched files pass the lint rules.') | ||
log.print('') | ||
} | ||
} else { | ||
log.log('No Stylelint configuration found') | ||
} | ||
|
||
if (configured('prettier')) { | ||
log.info('css > prettier') | ||
prettier({ | ||
apply, | ||
files: cssFiles, | ||
callback: finalStatus, | ||
}) | ||
} else { | ||
log.log('No Prettier configuration found') | ||
} | ||
|
||
if (!callback) { | ||
log.debug(sayFilesChecked('css', cssFiles.length, apply)) | ||
exit(finalStatus()) | ||
} | ||
|
||
return cssFiles.length | ||
} |
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,10 @@ | ||
const { bin } = require('@dhis2/cli-helpers-engine').exec | ||
const { PACKAGE_ROOT } = require('../utils/paths.js') | ||
|
||
exports.stylelint = ({ files = [], apply = false, callback }) => { | ||
const cmd = 'stylelint' | ||
const cwd = PACKAGE_ROOT | ||
const args = [...(apply ? ['--fix'] : []), ...files] | ||
|
||
bin(cmd, { args, cwd }, callback) | ||
} |
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,5 @@ | ||
const { config } = require('@dhis2/cli-style') | ||
|
||
module.exports = { | ||
extends: [config.stylelint], | ||
} |
Oops, something went wrong.