File tree 11 files changed +211
-0
lines changed
11 files changed +211
-0
lines changed Original file line number Diff line number Diff line change
1
+ node_modules /**
2
+ .idea /**
3
+ build /**
Original file line number Diff line number Diff line change
1
+ {
2
+ "env": {
3
+ "node": true
4
+ }
5
+ }
Original file line number Diff line number Diff line change
1
+ * .iml
2
+ .idea /
3
+ node_modules /
4
+ build /
5
+ npm-debug.log
Original file line number Diff line number Diff line change
1
+ .git *
2
+ build /
3
+ test /
4
+ .travis.yml
5
+ * .iml
6
+ .idea /
7
+ npm-debug.log
Original file line number Diff line number Diff line change
1
+ language : node_js
2
+ node_js :
3
+ - " 0.10"
4
+ after_success :
5
+ - npm run coveralls
Original file line number Diff line number Diff line change
1
+ # eslint-plugin-filenames
2
+
3
+ [ ![ NPM Version] ( https://img.shields.io/npm/v/eslint-plugin-filenames.svg?style=flat-square )] ( https://www.npmjs.org/package/eslint-plugin-filenames )
4
+ [ ![ Build Status] ( https://img.shields.io/travis/selaux/eslint-plugin-filenames.svg?style=flat-square )] ( https://travis-ci.org/selaux/eslint-plugin-filenames )
5
+ [ ![ Coverage Status] ( https://img.shields.io/coveralls/selaux/eslint-plugin-filenames.svg?style=flat-square )] ( https://coveralls.io/r/selaux/eslint-plugin-filenames?branch=master )
6
+ [ ![ Dependencies] ( https://img.shields.io/david/selaux/eslint-plugin-filenames.svg?style=flat-square )] ( https://david-dm.org/selaux/eslint-plugin-filenames )
7
+
8
+ Adds [ eslint] ( http://eslint.org/ ) rules to ensure consistent filenames for your javascript files.
9
+
10
+ ## Rules
11
+
12
+ ### Consistent Filenames (filenames)
13
+
14
+ A rule to enforce a certain file naming convention.
15
+
16
+ The convention can be configured using a regular expression (the default is ` camelCase.js ` ):
17
+
18
+ ```
19
+ "filenames": [2, "^[a-z_]$"]
20
+ ```
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ module . exports = {
4
+ rules : {
5
+ filenames : require ( "./lib/rules/filenames" )
6
+ }
7
+ } ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Rule to ensure that filenames match a convention (default: camelCase)
3
+ * @author Stefan Lau
4
+ */
5
+
6
+ //------------------------------------------------------------------------------
7
+ // Rule Definition
8
+ //------------------------------------------------------------------------------
9
+
10
+ module . exports = function ( context ) {
11
+
12
+ "use strict" ;
13
+
14
+ var path = require ( "path" ) ;
15
+
16
+ var defaultRegexp = / ^ ( [ a - z 0 - 9 ] + ) ( [ A - Z ] [ a - z 0 - 9 ] + ) * $ / g,
17
+ conventionRegexp = context . options [ 0 ] ? new RegExp ( context . options [ 0 ] ) : defaultRegexp ;
18
+
19
+ //--------------------------------------------------------------------------
20
+ // Helpers
21
+ //--------------------------------------------------------------------------
22
+
23
+ function matchesConvention ( filenameWithoutExtension ) {
24
+ return conventionRegexp . test ( filenameWithoutExtension ) ;
25
+ }
26
+
27
+ function report ( node , filename ) {
28
+ context . report ( node , "Filename '{{name}}' does not match the naming convention." , { name : filename } ) ;
29
+ }
30
+
31
+ return {
32
+ "Program" : function ( node ) {
33
+ var filename = context . getFilename ( ) ,
34
+ extension = path . extname ( filename ) ,
35
+ filenameWithoutExtension = path . basename ( filename , extension ) ;
36
+
37
+ if ( ! matchesConvention ( filenameWithoutExtension ) ) {
38
+ report ( node , filename ) ;
39
+ }
40
+ }
41
+ } ;
42
+
43
+ } ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " eslint-plugin-filenames" ,
3
+ "version" : " 0.0.1" ,
4
+ "description" : " Eslint rule for consistent filenames." ,
5
+ "main" : " index.js" ,
6
+ "scripts" : {
7
+ "test" : " npm run lint && npm run unit-test --coverage && npm run check-coverage" ,
8
+ "lint" : " eslint ." ,
9
+ "unit-test" : " istanbul test --dir build/coverage _mocha test -- --recursive --reporter dot" ,
10
+ "check-coverage" : " istanbul check-coverage --statement 100 --branch 100 --function 100 --lines 100" ,
11
+ "report-coverage-html" : " istanbul report --dir build/coverage html" ,
12
+ "coveralls" : " cat ./build/coverage/lcov.info | coveralls"
13
+ },
14
+ "devDependencies" : {
15
+ "chai" : " 1.10.0" ,
16
+ "eslint-tester" : " 0.4.0" ,
17
+ "istanbul" : " 0.3.5" ,
18
+ "mocha" : " 2.1.0" ,
19
+ "eslint" : " >=0.9.0" ,
20
+ "coveralls" : " 2.11.2"
21
+ },
22
+ "peerDependencies" : {
23
+ "eslint" : " >=0.9.0"
24
+ },
25
+ "repository" : {
26
+ "type" : " git" ,
27
+ "url" : " git://github.com/selaux/eslint-plugin-filenames.git"
28
+ },
29
+ "author" :
" Stefan Lau <[email protected] >" ,
30
+ "license" : " MIT" ,
31
+ "bugs" : {
32
+ "url" : " https://github.com/selaux/eslint-plugin-filenames/issues"
33
+ },
34
+ "homepage" : " https://github.com/selaux/eslint-plugin-filenames" ,
35
+ "keywords" : [
36
+ " eslint" ,
37
+ " eslintplugin" ,
38
+ " eslint-plugin" ,
39
+ " file" ,
40
+ " filename" ,
41
+ " path"
42
+ ]
43
+ }
Original file line number Diff line number Diff line change
1
+ var mocha = require ( "mocha" ) ,
2
+ expect = require ( "chai" ) . expect ,
3
+ index = require ( "../index.js" ) ,
4
+ rule = require ( "../lib/rules/filenames" ) ;
5
+
6
+ mocha . describe ( "index.js" , function ( ) {
7
+ "use strict" ;
8
+
9
+ mocha . it ( "should export the filenames rule" , function ( ) {
10
+ expect ( index . rules . filenames ) . to . equal ( rule ) ;
11
+ } ) ;
12
+ } ) ;
Original file line number Diff line number Diff line change
1
+ var linter = require ( "eslint" ) . linter ,
2
+ ESLintTester = require ( "eslint-tester" ) ;
3
+
4
+ var eslintTester = new ESLintTester ( linter ) ,
5
+ testCode = "var foo = 'bar';" ;
6
+
7
+ eslintTester . addRuleTest ( "lib/rules/filenames" , {
8
+
9
+ valid : [
10
+ {
11
+ code : testCode ,
12
+ filename : "foobar.js"
13
+ } ,
14
+ {
15
+ code : testCode ,
16
+ filename : "fooBar.js"
17
+ } ,
18
+ {
19
+ code : testCode ,
20
+ filename : "foo1Bar1.js"
21
+ } ,
22
+ {
23
+ code : testCode ,
24
+ filename : "foo_bar.js" ,
25
+ args : [ 1 , "^[a-z_]+$" ]
26
+ }
27
+ ] ,
28
+
29
+ invalid : [
30
+ {
31
+ code : testCode ,
32
+ filename : "foo_bar.js" ,
33
+ errors : [
34
+ { message : "Filename 'foo_bar.js' does not match the naming convention." , column : 0 , line : 0 }
35
+ ]
36
+ } ,
37
+ {
38
+ code : testCode ,
39
+ filename : "fooBAR.js" ,
40
+ errors : [
41
+ { message : "Filename 'fooBAR.js' does not match the naming convention." , column : 0 , line : 0 }
42
+ ]
43
+ } ,
44
+ {
45
+ code : testCode ,
46
+ filename : "fooBar$.js" ,
47
+ errors : [
48
+ { message : "Filename 'fooBar$.js' does not match the naming convention." , column : 0 , line : 0 }
49
+ ]
50
+ } ,
51
+ {
52
+ code : testCode ,
53
+ filename : "fooBar.js" ,
54
+ args : [ 1 , "^[a-z_]$" ] ,
55
+ errors : [
56
+ { message : "Filename \'fooBar.js\' does not match the naming convention." , column : 0 , line : 0 }
57
+ ]
58
+ }
59
+ ]
60
+
61
+ } ) ;
You can’t perform that action at this time.
0 commit comments