Skip to content

Commit 3939218

Browse files
committed
[Release] v1.2.0
1 parent d0d549a commit 3939218

File tree

7 files changed

+68
-52
lines changed

7 files changed

+68
-52
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v1.2.0 (October 08, 2018)
2+
3+
* Feature: eslint --fix param, auto replace camelCase to snake_case
4+
5+
16
# v1.1.0 (October 01, 2018)
27

38
* Feature: whitelist array on `eslintrc.json`

INSTALL.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
#### Setup
2-
1. Add dependencies on `package.json`
3-
```
4-
"dependencies": {
5-
"eslint": "^4.19.1",
6-
},
7-
"devDependencies": {
8-
"eslint-plugin-snakecasejs": "^1.1.0",
9-
}
10-
```
11-
2. Create `.eslintrc.json` file with:
2+
1. Install eslint: `npm install eslint -g`
3+
2. Install snakecasejs plugin in your project: `npm install eslint-plugin-snakecasejs --save-dev`
4+
3. Create `.eslintrc.json` file with:
125
```
136
{
147
"plugins": [
@@ -20,4 +13,6 @@
2013
"snakecasejs/whitelist": []
2114
}
2215
}
23-
```
16+
```
17+
4. If it works add a star :star: at this project :heart:
18+
5. If you want to help me: **[donate on paypal](http://paypal.ptkdev.io)** or become a **[backer on patreon](http://patreon.ptkdev.io)**.

ISSUE_TEMPLATE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
Replace the values below with your own:
44

5-
- **Plugin Version:** v1.0.0
5+
- **Plugin Version:** v1.2.0
66
- **Node Version:** v8.9 (Plugin require >= 7.6)
77
- **Operating System:** Ubuntu 14.04
8-
- **Browser:** Google Chrome 64
98

109

1110
### Expected Behavior

README.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# ESLint Plugin snakecasejs
44

5-
[![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](#) [![](https://img.shields.io/badge/powered%20by-eslint-46aef7.svg)](https://www.npmjs.com/package/eslint) [![](https://img.shields.io/badge/version-v1.1.0-lightgrey.svg)](https://github.com/ptkdev/eslint-plugin-snakecasejs/releases) [![](https://img.shields.io/badge/chat%20on-slack-orange.svg)](http://slack.ptkdev.io) [![](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](http://discord.ptkdev.io) [![](https://img.shields.io/badge/blog-medium-2AE176.svg)](http://blog.ptkdev.io) [![](https://img.shields.io/badge/twitter-ptkdevio-2AA3EF.svg)](https://twitter.com/ptkdevio)
5+
[![](https://img.shields.io/badge/license-MIT-brightgreen.svg)](#) [![](https://img.shields.io/badge/powered%20by-eslint-46aef7.svg)](https://www.npmjs.com/package/eslint) [![](https://img.shields.io/badge/version-v1.2.0-lightgrey.svg)](https://github.com/ptkdev/eslint-plugin-snakecasejs/releases) [![](https://img.shields.io/badge/chat%20on-slack-orange.svg)](http://slack.ptkdev.io) [![](https://img.shields.io/badge/chat%20on-discord-7289da.svg)](http://discord.ptkdev.io) [![](https://img.shields.io/badge/blog-medium-2AE176.svg)](http://blog.ptkdev.io) [![](https://img.shields.io/badge/twitter-ptkdevio-2AA3EF.svg)](https://twitter.com/ptkdevio)
66

77
[![](https://img.shields.io/badge/donate-patreon-F87668.svg)](http://patreon.ptkdev.io) [![](https://img.shields.io/badge/donate-paypal-46AFE0.svg)](http://paypal.ptkdev.io) [![](https://img.shields.io/badge/buy%20me-coffee-4B788C.svg)](http://coffee.ptkdev.io) [![](https://img.shields.io/badge/help-support@ptkdev.io-fbbc05.svg)](mailto:support@ptkdev.io)
88

@@ -12,21 +12,15 @@ This is to enforce a style of snake_case in your project, rather than just disab
1212
## Features
1313
* [] Easy to use
1414
* [] MIT License
15-
* [] Compatible with last version of ESLint
15+
* [] Compatible with latest version of ESLint
1616
* [] Compatible with CamelCase (Class name or similar)
17+
* [] Compatible with --fix (convert automatically camelCase to snake_case)
1718
* [] Whitelist array for methods or variables with camelCase syntax from other libraries/npm package.
1819

1920
## Fast setup
20-
1. Add dependencies on `package.json`
21-
```
22-
"dependencies": {
23-
"eslint": "^4.19.1",
24-
},
25-
"devDependencies": {
26-
"eslint-plugin-snakecasejs": "^1.1.0",
27-
}
28-
```
29-
2. Create `.eslintrc.json` file with:
21+
1. Install eslint: `npm install eslint -g`
22+
2. Install snakecasejs plugin: `npm install eslint-plugin-snakecasejs --save-dev`
23+
3. Create `.eslintrc.json` file with:
3024
```
3125
{
3226
"plugins": [
@@ -39,15 +33,19 @@ This is to enforce a style of snake_case in your project, rather than just disab
3933
}
4034
}
4135
```
42-
3. If it works add a star :star: at this project :heart:
43-
4. If you want to help me: **[donate on paypal](http://paypal.ptkdev.io)** or become a **[backer on patreon](http://patreon.ptkdev.io)**.
36+
4. If it works add a star :star: at this project :heart:
37+
5. If you want to help me: **[donate on paypal](http://paypal.ptkdev.io)** or become a **[backer on patreon](http://patreon.ptkdev.io)**.
4438

4539
NOTE: switch `error` to `warn` if you don't need snake_case as mandatory rules.
4640

4741
For advanced configuration see [INSTALL.md](https://github.com/ptkdev/eslint-plugin-snakecasejs/blob/master/INSTALL.md).
4842

49-
## Ignore words, variables, methods, class name (whitelist)
50-
Add rules: `"snakecasejs/whitelist": []` with array of variables or method with camelCase syntax.
43+
## --fix
44+
This eslint param fix simple rules of linter and with this plugin convert all camelCase variables or function name to snake_case. --fix support whitelist. Run this command in your project dir:
45+
- `eslint ./ --cache --ignore-pattern .gitignore --fix`
46+
47+
## Whitelist
48+
Ignore words, variables, methods, class name without snake_case syntax. Add rules: `"snakecasejs/whitelist": []` with array of variables or method with camelCase that you can not convert to snake_case (external library naming convention).
5149

5250
Plugin ignore check on this words. Example: `"snakecasejs/whitelist": ["externalPath","setNumber"]`
5351

package.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "eslint-plugin-snakecasejs",
3-
"description": "Eslint plugin to enforce a style of snake_case in your project, rather than just disabling camelcase.",
4-
"version": "1.1.0-5",
5-
"main": "index.js",
3+
"description": "Eslint plugin to enforce a style of snake_case in your project, rather than just disabling camelCase.",
4+
"version": "1.2.0",
5+
"main": "plugin.js",
66
"author": "Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)",
77
"author_original": "David Buchan-Swanson <david.buchanswanson@gmail.com>",
88
"license": "MIT",
9-
"homepage": "https://github.com/ptkdev",
9+
"homepage": "https://ptkdev.io",
1010
"bugs": {
1111
"url": "https://github.com/ptkdev/eslint-plugin-snakecasejs/issues"
1212
},
@@ -15,7 +15,7 @@
1515
"url": "https://github.com/ptkdev/eslint-plugin-snakecasejs.git"
1616
},
1717
"scripts": {
18-
"start": "node index.js",
18+
"start": "node plugin.js",
1919
"test": "node test.js",
2020
"lint": "eslint ./ --cache --ignore-pattern .gitignore --fix",
2121
"precommit-lint-check": "echo 'Pre-commit lint checks...' && exit 0"
@@ -30,18 +30,15 @@
3030
"snakecase",
3131
"snakecase-javascript",
3232
"underscore-syntax",
33-
"programming style",
34-
"coding conventions",
33+
"programming-style",
34+
"conventions",
3535
"syntax",
3636
"coding-style",
3737
"eslint",
3838
"eslint-plugin",
3939
"eslint-plugin-snakecase",
4040
"eslint-plugin-snakecasejs"
4141
],
42-
"dependencies": {
43-
"eslint": "^4.19.1"
44-
},
4542
"engines": {
4643
"node": ">=7.6.0"
4744
},
@@ -50,7 +47,7 @@
5047
"eslint-plugin-import": "^2.11.0",
5148
"eslint-plugin-node": "^6.0.1",
5249
"eslint-plugin-promise": "^3.7.0",
53-
"eslint-plugin-snakecasejs": "^1.1.0",
50+
"eslint-plugin-snakecasejs": "latest",
5451
"eslint-plugin-standard": "^3.1.0",
5552
"pre-commit": "^1.2.2"
5653
}

index.js renamed to plugin.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
/**
2-
* snakecasejs
2+
* ESLint: snakecasejs
33
* =====================
44
* This is to enforce a style of snake_case in your project, rather than just disabling camelcase.
55
*
66
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)
77
* @original: David Buchan-Swanson <david.buchanswanson@gmail.com>
88
* @license: This code and contributions have 'MIT License'
9-
* @version: 1.1.0
10-
* @changelog: 1.0.0 initial release
11-
* 1.1.0 add whitelist
129
*
1310
*/
1411
let eslintrc = null;
@@ -18,14 +15,32 @@ try {
1815
eslintrc = [];
1916
}
2017

21-
if(typeof eslintrc.rules["snakecasejs/whitelist"] == "undefined"){
18+
/**
19+
* Whitelist exist?
20+
* =====================
21+
* Set empry array if whitelist is undefined in eslintrc
22+
*
23+
*/
24+
if (typeof eslintrc.rules["snakecasejs/whitelist"] == "undefined") {
2225
eslintrc.rules["snakecasejs/whitelist"] = [];
2326
}
2427

25-
function is_class_usage(node) {
28+
/**
29+
* Detect var and function
30+
* =====================
31+
* Filter code, find funcrions name and variables
32+
*
33+
*/
34+
function filter(node) {
2635
return ["FunctionDeclaration", "NewExpression", "MemberExpression"].indexOf(node.parent.type) > -1;
2736
}
2837

38+
/**
39+
* Detect function and variables name
40+
* =====================
41+
* Filter code, find functions name and variables
42+
*
43+
*/
2944
module.exports = {
3045
rules: {
3146
snakecasejs: {
@@ -36,22 +51,31 @@ module.exports = {
3651
return {
3752
Identifier(node) {
3853
var name = node.name;
54+
55+
// ignore javascript language function
3956
var array_system_var = ["parseInt", "parseFloat", "isNaN", "isFinite", "decodeURI", "decodeURIComponent", "encodeURI", "toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "indexOf", "forEach", "charAt", "charCodeAt", "endsWith", "lastIndexOf", "startsWith", "toLowerCase", "toLocaleLowerCase", "toUpperCase", "toLocaleUpperCase", "toFixed", "toPrecision", "setInterval", "clearInterval", "setTimeout", "toDateString", "toTimeString", "getTime", "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate", "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes", "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds", "getUTCMilliseconds", "getTimeZoneOffset", "setTime", "setMilliseconds", "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes", "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate", "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toUTCString", "toISOString", "toJSON"];
57+
4058
var split = name.split(/(?=[A-Z])/);
4159
var split_az = name.split(/(?=[a-z])/);
60+
61+
// detect camelCase
4262
if ((split.length > 1 && split_az.length > 1) && !array_system_var.includes(name) && !eslintrc.rules["snakecasejs/whitelist"].includes(name)) {
43-
if (is_class_usage(node)) {
63+
if (filter(node)) {
4464
return true;
4565
}
66+
67+
// error message on ide
4668
context.report({
4769
message: "Identifiers must be snake_case: {{ identifier }}",
4870
node: node,
4971
data: {
5072
identifier: node.name,
5173
},
52-
// fix(fixer) {
53-
// return fixer.replaceText(node, split.map(function(piece){ return piece.replace('_', '').toLowerCase(); }).join('_'));
54-
// }
74+
75+
// --fix eslint param: detect camelCase and convert in snake_case
76+
fix(fixer) {
77+
return fixer.replaceText(node, node.name.split(/(?=[A-Z])/).join("_").toLowerCase());
78+
}
5579
});
5680
}
5781
}

test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* @author: Patryk Rzucidlo [@ptkdev] <support@ptkdev.io> (https://ptkdev.it)
77
* @original: David Buchan-Swanson <david.buchanswanson@gmail.com>
88
* @license: This code and contributions have 'MIT License'
9-
* @version: 1.0.0
10-
* @changelog: 1.0.0 initial release
119
*
1210
*/
1311
var rule_tester = require("eslint").RuleTester;

0 commit comments

Comments
 (0)