Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@pitcher/eslint-config
Advanced tools
Code style guide and ESLint configuration for JavaScript & Vue projects
Code style guide for JavaScript & Vue projects, eslint rule package
There are multiple ways to apply pitcher-code-style to your project.
If you want to apply ESLint configuration to a Vue project, this way might be the easiest way for you.
NOTE: If your project is not a Vue project, this option will NOT work.
vue add @pitcher/pitcherify
code-style - Pitcher ESLint config
option with space, press EnterThis option might consume a bit more time than Option 1, but you have freedom to apply these settings to plain JavaScript projects as well.
eslint
version >=7.14.0
prettier
version >=1.19.1
(works with 2+ as well)babel-eslint
version >=10.1.0"
eslint-plugin-vue
version >=7.8.0
eslint-plugin-prettier
version >=3.1.4
@vue/eslint-config-prettier
version >=6.0.0
npm install -D @pitcher/eslint-config
.eslintrc.js
or .eslintrc.json
file add
extends: ["@pitcher"]
or extends: ["@pitcher/eslint-config/vue"]
extends: ["@pitcher/eslint-config/javascript"]
extends: ["@pitcher/eslint-config/essential"]
prettier.config.js
withmodule.exports = require('@pitcher/eslint-config/prettier.config')
NOTE: By default the package exports Vue configuration. So using
extends: ["@pitcher"]
would work in most cases even for plain JavaScript projects.
npm install -D eslint@7.14.0 prettier@1.19.1 babel-eslint@10.1.0 eslint-plugin-vue@7.8.0 eslint-plugin-prettier@3.1.4 @vue/eslint-config-prettier@6.0.0
module.exports = {
root: true,
env: {
node: true,
},
extends: ['@pitcher'],
parserOptions: {
parser: 'babel-eslint',
},
}
module.exports = require('@pitcher/eslint-config/prettier.config')
Pitcher Code Style package even includes an ESLint & Prettier configuration for ES5 projects. Installation and usage of the configuration differs a little bit than ES6 based projects.
To use the ESLint configuration with your ES5 based projects, follow the steps below:
package.json
file, create it with the command below first:npm init --yes
npm install -D eslint@7.14.0 prettier@1.19.1 @pitcher/eslint-config eslint-plugin-prettier@3.1.4
.eslintrc.js
in your project root and copy the code below and paste into the new created filemodule.exports = {
root: true,
env: {
node: true,
browser: true,
},
plugins: ['prettier'],
extends: ['@pitcher/eslint-config/es5'],
// file/folder names to ignore linting
ignorePatterns: ['**/*.min.js', '**/bootstrap*', '**/jquery*', '**/kendo*', 'node_modules'],
}
prettier.config.json
in your project root and copy the code below and paste into the new created filemodule.exports = require('@pitcher/eslint-config/prettier.config.es5')
"scripts"
section in your package.json
, and add the file/folder path you want to lint"scripts": {
"lint": "eslint YOUR_FILE_PATH_TO_LINT --fix"
},
eslint src/js/pitcher.js
- lints only pitcher.js
fileeslint src/js/
- lints everyting under src/js
foldereslint src/**/*.js
- lints all the *.js
files that is under src
folderTIP If you dont want ESLint to fix the errors/warnings automatically but just to see the current code problems you can use
--fix-dry-run
argument to execute a dry run.
To use pre-defined VSCode settings/extensions/snippets:
To use pre-defined IntelliJ code style configuration:
config/code-style.jetbrains.xml
fileStyle rules that are presented here are based on best-practices in JavaScript ecosystem. Most of the rules here are enforced through eslint and it is strongly recommended to follow. Some of the rules might not apply depending on your project size.
├── locale/
├── public/
├── src/
│ ├── assets/
│ ├── components/
│ ├── router/
│ ├── store/
│ ├── views/
│ ├── App.vue
│ └── main.js
├── .env
├── gettext.config.js
├── ti-web-config.json
gettext
index.html
etc. JS/CSS files are injected to index.html
automatically when you build your projectgettext
ti-web
. This file is used to fetch local db & simulate ti environment to be able to run the project on a browsername
property written in PascalCasecomponents/list
folder contains List.vue
, ListItem.vue
, ListHeader.vue
Example
├─ components/
│ ├── Card.vue
│ ├── Footer.vue
│ └── List/
│ ├── List.vue
│ ├── ListHeader.vue
│ └── ListItem.vue
.view
suffix e.g. AppLogin.view.vue
, AppList.view.vue
name
property written in PascalCase e.g. name: 'AppLogin'
views/AppLogin
folder contains AppLogin.view.vue
and AppLogin.route.js
Example (small projects)
├─ views/
│ ├── Home.view.vue
│ ├── Login.view.vue
│ └── etc.
Example (mid/large projects, where views and their routes are contained together)
├─ views/
│ │
│ ├── home
│ │ ├── Home.view.vue
│ │ └── Home.router.js
│ │
│ ├── login
│ │ ├── Login.view.vue
│ │ └── Login.router.js
│ │
│ └── etc.
All Vue related eslint rules are provided by eslint-plugin-vue. We take plugin:vue/vue3-strongly-recommended
set as a base and on the top of it we have a couple of custom rules. These rules exist in vue.js
. We also have prettier
plugin installed which helps us to lint/format vue files.
Use always shorthands when using template bindings. The reason for this is to keep template part clean and readable
Closing tags Use always self closing tag when applicable
<!-- ✗ BAD -->
<i class="fa fa-times"></i>
<!-- ✓ GOOD -->
<i class="fa fa-times" />
Props/Data
<!-- ✗ BAD -->
<input v-bind:value="value" />
<!-- ✓ GOOD -->
<input :value="value" />
Events
<!-- ✗ BAD -->
<input v-on:click="handleClick" />
<!-- ✓ GOOD -->
<input @click="handleClick" />
Named slots
<!-- ✗ BAD -->
<template v-slot:header></template>
<!-- ✓ GOOD -->
<template #header></template>
To be updated
For JavaScript linting we do use eslint:recommended
set as a base. A couple of custom rules on the top of recommended set exist in javascript.js
. We also have prettier
plugin installed which helps us to lint/format javascript files.
When applicable/needed, you can use BEM methodology to get a clear understanding of your html. If BEM is not applicable/needed, do follow the naming conventions below.
It is required to use kebab-case
when adding classes to your elements. This helps us to separate variables and css classes when reading the code, also provides us more readable/maintainable code on scss/less part.
Example
<!-- ✗ BAD -->
<template>
<div class="testParent">
<span class="testChild"></span>
</div>
</template>
<style lang="scss">
.testParent {
background-color: red;
}
.testChild {
color: white;
}
</style>
<!-- ✓ GOOD -->
<template>
<div class="test-parent">
<span class="test-child"></span>
</div>
</template>
<style lang="scss">
.test-parent {
background-color: red;
.test-child {
color: white;
}
}
</style>
<!-- ✓✓ EVEN BETTER with BEM -->
<template>
<div class="test">
<span class="test__header"></span>
<span class="test__subheader"></span>
</div>
</template>
<style lang="scss">
.test {
background-color: red;
&__header {
color: white;
}
&__subheader {
color: grey;
}
}
</style>
README.md
with visual examplesFAQs
Code style guide and ESLint configuration for JavaScript & Vue projects
The npm package @pitcher/eslint-config receives a total of 106 weekly downloads. As such, @pitcher/eslint-config popularity was classified as not popular.
We found that @pitcher/eslint-config demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.