What I wanna achieve
Intellij - show error via red underline
Validate formating via NPM
Autoformating via save
Override printWidth to 140
Integrate with stylelint and tslint and file watcher
What I have done
stylelint.config.js
const regex = {
pascal: "[A-Z][a-z]+[a-zA-Z]*",
camel: "[a-z]+[a-zA-Z]*"
};
const componentElementModifier = `\\.${regex.pascal}(__${regex.camel}(_${regex.camel})?)?`;
const componentModifier = `\\.${regex.pascal}_${regex.camel}`;
const bemMix = `\\.${regex.pascal}__${regex.pascal}`;
module.exports = {
plugins: ["stylelint-prettier", "stylelint-selector-bem-pattern"],
extends: ["stylelint-prettier/recommended"],
rules: {
"prettier/prettier": true,
"plugin/selector-bem-pattern": {
componentName: regex.pascal,
implicitComponents: true,
componentSelectors: {
initial: `^(${componentElementModifier})$|^(${bemMix})$|^(${componentModifier})$`
}
}
}
};
tslint.json
{
"extends": [
"tslint:latest",
"tslint-react",
"tslint-plugin-prettier",
"tslint-config-prettier"
],
"rules": {
"object-literal-sort-keys": false,
"prettier": true,
"no-default-export": true
},
"linterOptions": {
"exclude": ["**/*.less.d.ts"]
}
}
Intellij Idea - File Watcher configuration
Intellij Idea - TSlint configuration
Intellij Idea - Typescript configuration
packge.json - stylelint config + runners
What my questions
How to add printWidth 140 to all configs?
How to share prittier config into tslint and stylelint?
How to make it works with runners in package.json and file watcher
How to add printWidth 140 to all configs?
I'd suggest setting it in your .prettierrc
How to share prittier config into tslint and stylelint?
tslint will use your prettier config for linting/autofixes if you configure it accordingly. Same is true for stylelint
How to make it works with runners in package.json and file watcher
not sure I follow you... I'd suggest removing Prettier file watcher and only use tslint and stylelint for formatting your code. You can configure them as file watchers if you like to fix code style issues on Save and/or add npm scripts to your package.json that would run tslint --fix and stylelint --fix commands
Related
I am using fullcalendar with vue3. I want to change change colors for button and text in fullcalendar.
vue version
"vue": "^3.2.26",
I am getting error
Syntax Error: Error: PostCSS plugin postcss-custom-properties requires
PostCSS 8.
I am following steps mentioned in fullcalendar documentation.
fullcalendar-vars.css
:root {
--fc-border-color: green;
--fc-button-text-color: #ff0000;
}
I have installed following packages
"postcss": "^8.4.7",
"postcss-calc": "^8.2.4",
"postcss-custom-properties": "^12.1.4",
"postcss-loader": "^6.2.1",
Added postcss.config.js at root
module.exports = {
plugins: [
require('postcss-custom-properties')({
preserve: false, // completely reduce all css vars
importFrom: [
'client/fullcalendar-vars.css' // look here for the new values
]
}),
require('postcss-calc')
]
}
And my vue.config.js as follow
const path = require("path");
module.exports = {
pages: {
index: {
entry: "./client/main.js",
},
},
outputDir: path.resolve(__dirname, "./client/dist"),
};
Also I would like to know, Do I need make any changes in vue.config.js?
PostCSS error
Vue CLI scaffolded projects already include PostCSS (including postcss, postcss-calc, and postcss-loader), so you don't need to install it in your project. The only dependency needed here is postcss-custom-properties.
To resolve the PostCSS error, you should uninstall the PostCSS dependencies that you had mistakenly added:
npm uninstall --save-dev postcss postcss-calc postcss-loader
Starting from scratch
To setup custom colors for FullCalendar in a Vue CLI scaffolded project:
Install postcss-custom-properties with:
npm install --save-dev postcss-custom-properties
Create postcss.config.js with the following PostCSS configuration:
// <projectRoot>/postcss.config.js
module.exports = {
plugins: [
require("postcss-custom-properties")({
preserve: false,
importFrom: [
"client/fullcalendar-vars.css",
],
}),
require("postcss-calc"),
],
}
Create fullcalendar-vars.css with the following CSS:
/* <projectRoot>/client/fullcalendar-vars.css */
:root {
--fc-border-color: green;
--fc-button-text-color: #ff0000;
}
Note: Changes to this file are not hot-reloaded, so the dev server must be restarted to reflect any updates.
Start the Vue CLI dev server with:
npm run serve
demo
I have a Gruntfile.js like this.
module.exports = function(grunt) {
require('time-grunt')(grunt);
require('load-grunt-config')(grunt, {
jitGrunt: {
staticMappings: {
scsslint: 'grunt-scss-lint'
}
}
});
grunt.loadNpmTasks('grunt-run');
grunt.registerTask('default', ['eslint', 'jest', 'scsslint', 'svgstore'])
};
And when I run the grunt it says.
grunt
No "eslint" targets found.
eslint is already installed and I even created the configuration file using
./node_modules/.bin/eslint --init
And this is the content of .eslintrc.js.
module.exports = {
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 13
},
"rules": {
}
};
Any opinions?
Depending on how you downloaded the codebase for the theme, it may be missing the "grunt" folder. If your project is missing this folder, try adding the one from Cornerstone: https://github.com/bigcommerce/cornerstone/tree/master/grunt
Per the BigCommerce documentation around eslint errors -- If bundling your theme triggers multiple lint errors related to the bundle.js file, your theme is missing the .eslintignore file.
You can retrieve this file from the Cornerstone repo. Once you add this in, re-run the bundle command.
I have a simple project generated with vue-cli. When I run the vue-cli-service build command it produces CSS file correctly. When I run the vue-cli-service build --watch command it only builds JavaScript files. There are no CSS files.
How can I generate CSS files in watch mode?
You can achieve this by adding this line of code in your vue.config.js
//vue.config.js
module.exports = {
//adding extract css true solves this issue
css: {
extract: true
}
}
https://cli.vuejs.org/config/#css-extract
There is a good chance that you have to use an extract plugin for webpack.
I know that in my vue.config.js file I'm using :
chainWebpack: config => {
if (config.plugins.has('extract-css')) {
const extractCSSPlugin = config.plugin('extract-css');
extractCSSPlugin &&
extractCSSPlugin.tap(() => [
{
filename: 'build.css',
chunkFilename: 'build.css'
}
]);
}
}
Hopefully this help you. However vue inject your css in watch mode right at the top of your file for automatic re-rendering purpose I think.
I am using create-react-app with craco (Create-React-App-Configuration-Override)
Craco is not very exotic. It simply allows me to use my own eslintrc file with create-react-app.
I am trying to use a custom eslint formatter, specifically eslint-formatter-friendly does what I need (link to files at line numbers via iTerm/Guake terminals), but there are plenty of alternative formatters: http://npmsearch.com/?q=eslint-formatter
I tried setting a format: 'unix' or formatter: 'unix' in my .eslintrc.js file - but this didn't work, eslint explicitly gave an error saying something like "unrecognized top-level property".
I looked for any way I could specify formatter in the .eslintrc.js file, but I figured out that's not an option. After searching and scanning through the source for gulp-eslint, eslint-grunt and grunt-eslint, eventually I looked more closely at the source for for craco - where is reads a little eslint configuration: https://github.com/sharegate/craco/blob/master/recipes/use-an-eslintrc-config-file/craco.config.js
The source that processes this: https://github.com/sharegate/craco/blob/master/packages/craco/lib/features/webpack/eslint.js
All I needed to do was use this craco.config.js:
/* globals module */
const { ESLINT_MODES } = require("#craco/craco");
const reactHotReloadPlugin = require('craco-plugin-react-hot-reload');
module.exports = {
plugins: [{
plugin: reactHotReloadPlugin
}],
eslint: {
mode: ESLINT_MODES.file,
loaderOptions: {
formatter: require("eslint-formatter-friendly")
}
},
};
I created a new nuxt app using npx create-nuxt-app <project-name> and chose to use eslint and prettier.
I opened the project's directory using vscode and installed the ESLint and Prettier - Code formatter, and Vetur extensions.
When I save a .vue file vscode formats the code, but in a way that breaks the settings in the nuxt project.
For example vscode transforms
<div
class="test"
style="background: red">
test
</div>
to
<div class="test" style="background: red">test</div>
but this breaks the vue/max-attributes-per-line rule.
How do I set up vscode to use the nuxt project's linting and prettyfying rules?
When starting a new nuxt project using npx create-nuxt-app, check both ESLint and Prettier for linting options and choose the recommended jsconfig.json option.
Then do the following:
install additional npm dev packages
npm install --save-dev babel-eslint eslint eslint-config-prettier eslint-loader eslint-plugin-vue eslint-plugin-prettier prettier
Install VS Code extensions
Prettier
ESLint
Vetur
Formatting Toggle (optional)
Change your workplace settings (.vscode/settings.json) to the following:
{
"eslint.format.enable": true,
"vetur.format.defaultFormatter.html": "prettier"
}
You can toggle auto fixing using the Formatting Toggle extension, or if you didn't install it by changing your user settings:
{
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true
}
Change your .prettierrc file (optional)
{
"semi": false,
"arrowParens": "always",
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"endOfLine": "lf"
}
Install the extensions:
Vue
Vue 2 Snippets
Vue Peek
Vetur
ESLint
Go to File > Preferences > Settings and edit the User Settings file, adding the following configuration:
{
...... ,
"vetur.format.defaultFormatter.js": "vscode-typescript",
"vetur.format.defaultFormatter.html": "js-beautify-html",
"javascript.format.insertSpaceBeforeFunctionParenthesis": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
{
"language": "vue",
"autoFix": true
},
{
"language": "html",
"autoFix": true
},
{
"language": "javascript",
"autoFix": true
}
],
}
With this configuration, VSCode will perform validation for these three file types: vue, HTML and JavaScript. Now go back to the src/App.vue file and press ctrl+alt+f on Windows or ctrl+shift+i on Linux or ctrl+options+f on Mac OS to perform the formatting of the code. ESLint will validate the code and display some errors on the screen.
Any errors can be corrected automatically, and it’s not necessary to correct each error manually. To do this, you can
press
ctrl+shift+p
and select
ESLint: Fix all problems