Skip to content

Commit

Permalink
chore(release): v0.0.1
Browse files Browse the repository at this point in the history
initial release
  • Loading branch information
janraasch committed Jan 21, 2014
0 parents commit 2c8bf24
Show file tree
Hide file tree
Showing 18 changed files with 506 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
.DS_Store
node_modules/
temp/
coverage/
*.log
index.js
Empty file added .npmignore
Empty file.
8 changes: 8 additions & 0 deletions .travis.yml
@@ -0,0 +1,8 @@
language: node_js
node_js:
- '0.10'
- '0.11'
before_script:
- npm config set coverage true
after_success:
- npm run-script coveralls
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,5 @@
<a name="0.0.1"></a>
### 0.0.1 (2014-01-21)

Initial release.

19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2014 Jan Raasch

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
42 changes: 42 additions & 0 deletions coffeelint.json
@@ -0,0 +1,42 @@
{
"indentation": {
"value": 4
},
"line_endings": {
"level": "error",
"value": "unix"
},
"colon_assignment_spacing": {
"name": "colon_assignment_spacing",
"level": "error",
"spacing": {
"left": 0,
"right": 1
}
},
"space_operators": {
"level": "error"
},
"newlines_after_classes": {
"value": 3,
"level": "error"
},
"no_stand_alone_at": {
"level": "error"
},
"arrow_spacing": {
"level": "error"
},
"cyclomatic_complexity": {
"level": "error"
},
"empty_constructor_needs_parens": {
"level": "error"
},
"no_empty_param_list": {
"level": "error"
},
"no_unnecessary_fat_arrows": {
"level": "error"
}
}
49 changes: 49 additions & 0 deletions gulpfile.coffee
@@ -0,0 +1,49 @@
fs = require 'fs'
{spawn} = require 'child_process'
gulp = require 'gulp'
coffee = require 'gulp-coffee'
coffeelint = require 'gulp-coffeelint'
clean = require 'gulp-clean'
{log,colors} = require 'gulp-util'

# compile `index.coffee`
gulp.task 'coffee', ->
gulp.src('index.coffee')
.pipe(coffee bare: true)
.pipe(gulp.dest './')

# remove `index.js` and `coverage` dir
gulp.task 'clean', ->
gulp.src(['index.js', 'coverage'], read: false)
.pipe(clean())

# run tests
gulp.task 'test', ['coffee'], ->
spawn 'npm', ['test'], stdio: 'inherit'

# create changelog
gulp.task 'changelog', ->
changelog = require 'conventional-changelog'
changelog({
repository: 'https://github.com/janraasch/generator-gulpplugin-coffee'
version: require('./package.json').version
}, (err, log) ->
fs.writeFileSync 'CHANGELOG.md', log
)

# test drive
gulp.task 'selfie', ->
usestrict = require './index.coffee'
gulp.src('./{,test/,test/fixtures/}*.coffee')
.pipe(coffeelint null, false, [usestrict])
.pipe(coffeelint.reporter())

# start workflow
gulp.task 'default', ->
gulp.run 'coffee'

gulp.watch ['./{,test/,test/fixtures/}*.coffee'], (e) ->
log "File #{e.type} #{colors.magenta e.path}"
gulp.run 'test'

# Generated on 2014-01-20 using generator-gulpplugin-coffee 0.0.2
105 changes: 105 additions & 0 deletions index.coffee
@@ -0,0 +1,105 @@
'use strict'
isUseStrictValue = (node) ->
(node.constructor.name is 'Value') and
node.isString() and
(node.base.value is '"use strict"' or
node.base.value is "'use strict'")

useStrictAtTopOf = (node) ->
firstChild = null

# let's not bother with empty nodes
# i.e. empty functions
return {boolean: true} if node.isEmpty()

# get first child
node.eachChild (child) ->
firstChild = child
false

# return result
boolean: isUseStrictValue firstChild
firstChild: firstChild

class UseStrictRule
rule:
name: 'use_strict'
level: 'error'
message: 'Missing \'use strict\' statement'
allowGlobal: true
requireGlobal: false
description: """
<p>This rule enforces the ussage of strict mode. By setting
requireGlobal to true, you can also require a file to
have a global 'use strict' statement at the top. And, by setting
allowGlobal to true (or false) you can allow
(or disallow) 'use strict' statements at the top of a file</p>
<pre><code>
#
# If requireGlobal is false
#
# Good
goodfunc = (please) ->
'use strict'
allright
# Bad
badfunc = (idonot) ->
obey
</code></pre>
"""

lintAST: (node, astApi) ->
createError = astApi.createError
{requireGlobal, allowGlobal} = astApi.config[@rule.name]
firstChild = null

# let's not bother with empty nodes
return undefined if node.isEmpty()

# check global `use strict`
useStrict = useStrictAtTopOf node
if useStrict.boolean is true
if allowGlobal is off
@errors.push(
createError(
lineNumber:
useStrict.firstChild.locationData.first_line + 1
message:
'\'use strict\' at top of file'
)
)
else
allowGlobal is on
# no errors and done
return undefined
else
if requireGlobal is true
@errors.push(
createError(
lineNumber:
useStrict.firstChild.locationData.first_line + 1
)
)
return undefined

# seems like we really need to walk down the tree
# and find find first level functions
node.traverseChildren false, (child) =>
useStr = null
if child.constructor.name is 'Code'
useStr = useStrictAtTopOf child.body
if not useStr.boolean
@errors.push(
createError(
lineNumber:
useStr.firstChild.locationData.first_line + 1
)
)
true

undefined


module.exports = UseStrictRule
53 changes: 53 additions & 0 deletions package.json
@@ -0,0 +1,53 @@
{
"name": "coffeelint-use-strict",
"version": "0.0.1",
"description": "A CoffeeLint rule that enforces usage of strict mode",
"keywords": [
"coffee",
"coffeescript",
"coffeelint",
"rule",
"usestrict",
"use strict",
"'use strict'",
"\"use strict\"",
"coffeelintrule",
"coffeelintmodule",
"coffeelint-rule",
"coffeelint-module",
"codeconventions"
],
"repository": "janraasch/coffeelint-use-strict",
"author": {
"name": "Jan Raasch",
"email": "jan@janraasch.com",
"url": "http://janraasch.com"
},
"files": [
"index.js"
],
"scripts": {
"prepublish": "gulp coffee --require coffee-script",
"test": "coffeelint gulpfile.coffee index.coffee test -f ./coffeelint.json && istanbul test _mocha --report lcovonly -- ./test/*.coffee --require coffee-script --reporter spec",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"screenshot": "coffeelint index.coffee"
},
"devDependencies": {
"coffee-script": "~1.6.3",
"coffeelint": "~1.0.2",
"mocha": "~1.17.0",
"gulp-util": "~2.2.12",
"istanbul": "~0.2.3",
"should": "~3.0.1",
"coveralls": "~2.6.1",
"gulp": "~3.4.0",
"gulp-coffee": "~1.2.2",
"gulp-clean": "~0.2.2",
"gulp-coffeelint": "~0.1.2",
"conventional-changelog": "0.0.4"
},
"engines": {
"node": ">=0.8.0"
},
"license": "MIT"
}
72 changes: 72 additions & 0 deletions readme.md
@@ -0,0 +1,72 @@
# coffeelint-use-strict [![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![devDependency Status][devdepstat-image]][devdepstat-url]

> [CoffeeLint][coffeelint] rule that enforces usage of [strict mode][moz-strictmode-doc].
![example-output](screenshot.png)

## Usage

First, install `coffeelint-use-strict` as a development dependency:

```shell
npm install --save-dev coffeelint-use-strict
```

Then, add a `"use_strict"` key with value `{"module": "coffeelint-use-strict"}` to your `coffeelint.json`, e.g.

```json
{
"use_strict": {
"module": "coffeelint-use-strict",
"level": "error",
"allowGlobal": false,
"requireGlobal": false
}
}
```

The `coffeelint` cli will then load this rule automatically. See the [documentation][coffeelint-api-doc] for other ways to make use of custom rules.

## Options

### level
Type: `String`
Default: `'error'`

The severity level of the violated rule. `level` must be one of `'ignore'`, `'warn'`, or `'error'`.

### allowGlobal
Type: `Boolean`
Default: `true`

Allow the `'use strict'` statement to be at the top of a file.

### requireGlobal
Type: `Boolean`
Default: `false`

Require the `'use strict'` statement to be at the top of a file.

## License

[MIT License](http://en.wikipedia.org/wiki/MIT_License) © [Jan Raasch](http://janraasch.com)

[coffeelint]: http://www.coffeelint.org
[coffeelint-api-doc]: http://www.coffeelint.org/#api
[moz-strictmode-doc]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FFunctions_and_function_scope%2FStrict_mode

[npm-url]: https://npmjs.org/package/coffeelint-use-strict
[npm-image]: https://badge.fury.io/js/coffeelint-use-strict.png

[travis-url]: http://travis-ci.org/janraasch/coffeelint-use-strict
[travis-image]: https://secure.travis-ci.org/janraasch/coffeelint-use-strict.png?branch=master

[coveralls-url]: https://coveralls.io/r/janraasch/coffeelint-use-strict
[coveralls-image]: https://coveralls.io/repos/janraasch/coffeelint-use-strict/badge.png

[depstat-url]: https://david-dm.org/janraasch/coffeelint-use-strict
[depstat-image]: https://david-dm.org/janraasch/coffeelint-use-strict.png

[devdepstat-url]: https://david-dm.org/janraasch/coffeelint-use-strict#info=devDependencies
[devdepstat-image]: https://david-dm.org/janraasch/coffeelint-use-strict/dev-status.png
Binary file added screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions test/fixtures/class-global.coffee
@@ -0,0 +1,14 @@
# what the
# sdsd#
#sfdsf
'use strict'
fuck = 'me'
->
fucker
class SomeClass
what: ->
isthis()
and: ->
what = ->
isthat()
other()

0 comments on commit 2c8bf24

Please sign in to comment.