Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nsaechao/add eslinter goal #5

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
28bb30c
Merge pull request #1 from pantsbuild/master
nsaechao Jul 11, 2017
ac47c06
Add javascriptstyle lint goal
Jul 31, 2017
cd91b30
Use a built node package for javascript linting and formatting
Aug 2, 2017
9845db9
Merge branch with master
Aug 2, 2017
76fbb73
undo changes for node_module.py
Aug 2, 2017
b462ea2
Add new line at end of file
Aug 2, 2017
3888611
Add --fail-slow flag for linting all targets before failing
Aug 2, 2017
053a704
Merge branch 'master' of https://github.com/nsaechao/pants
Aug 2, 2017
54e61ae
Merge pull request #3 from nsaechao/nsaechao/add_eslinter_goal
nsaechao Aug 2, 2017
5784d1a
Add blacklist for javascript style checking
Aug 3, 2017
6159fca
Add missing exclude.js file for blacklisting js file when running lin…
Aug 3, 2017
f10ae8c
Add python_library for javascript_style so it is discoverable
Aug 3, 2017
00fd49d
Fix python code to match pants style guideline for python
Aug 3, 2017
d6a8e1b
Rename NodeLineIntegrationTest to match file name
Aug 8, 2017
779306e
Skip javascriptstyle if it is not configured. Add documentation on ho…
Aug 11, 2017
e49dd91
Fix ** characters due to .md styling
Aug 15, 2017
96b1218
Merge branch 'master' into nsaechao/add_eslinter_goal
nsaechao Sep 26, 2017
5cad294
Fix typos and add comment about why javascriptstyle uses a mutable pa…
Sep 27, 2017
0522d52
Merge branch 'nsaechao/add_eslinter_goal' of https://github.com/nsaec…
Sep 27, 2017
6025ccd
Merge branch 'master' of https://github.com/pantsbuild/pants into nsa…
Sep 27, 2017
285db49
merged
Sep 27, 2017
7ae65bc
Merge branch 'pantsbuild-master'
Sep 27, 2017
1971551
Merge branch 'master' into nsaechao/add_eslinter_goal
nsaechao Sep 27, 2017
5e85c20
Remove irrelevant python test due to merge bug
Sep 27, 2017
1225525
Merge branch 'nsaechao/add_eslinter_goal' of https://github.com/nsaec…
Sep 27, 2017
3fcbf33
Add transitive as an option for javascript linting
Sep 27, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions build-support/javascriptstyle/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
// babel parser to support ES6/7 features
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 7,
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
],
"env": {
"es6": true,
"node": true,
"mocha": true,
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"array-bracket-spacing": ["error", "always"],
"arrow-parens": [2, "always"],
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"camelcase": 0,
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"computed-property-spacing": ["error", "never"],
"constructor-super": 2,
"curly": [2, "all"],
"default-case": [2, { commentPattern: '^no default$' }],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": 0,
"indent-legacy": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"max-len": [2, 120, 4],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-alert": 1,
"no-array-constructor": 2,
"no-caller": 2,
"no-case-declarations": 2,
"no-class-assign": 2,
"no-compare-neg-zero": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-duplicate-imports": 2,
"no-empty-character-class": 2,
"no-empty-pattern": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-extra-semi": 2,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": [2, { "allowLoop": false, "allowSwitch": false }],
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 2,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-symbol": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-path-concat": 2,
"no-proto": 2,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": [2, "except-parens"],
"no-script-url": 2,
"no-self-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unmodified-loop-condition": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unsafe-finally": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 2,
"no-useless-computed-key": 2,
"no-useless-concat": 2,
"no-useless-constructor": 2,
"no-useless-escape": 2,
"no-var": 2,
"no-whitespace-before-property": 2,
"no-with": 2,
"object-curly-spacing": ["error", "always"],
"operator-linebreak": [2, "after"],
"padded-blocks": [2, "never"],
"prefer-const": 2,
"prefer-rest-params": 2,
"prefer-template": 2,
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"require-yield": 2,
"rest-spread-spacing": ["error"],
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"sort-imports": ["error", { "memberSyntaxSortOrder": ["none", "all", "single", "multiple"], "ignoreCase": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [2, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"template-curly-spacing": [2, "never"],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "outside"],
"yield-star-spacing": [2, "both"],
"yoda": [2, "never"]
}
}
3 changes: 3 additions & 0 deletions build-support/javascriptstyle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.yarnclean
node_modules
yarn-error.log
1 change: 1 addition & 0 deletions build-support/javascriptstyle/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry='https://registry.yarnpkg.com'
62 changes: 62 additions & 0 deletions build-support/javascriptstyle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Setting up JavaScript Style Checker

1. Download the JavaScriptStyle package from https://github.com/pantsbuild/binaries/build-support/scripts/javascriptstyle
2. Unpack the javascriptstyle.tgz into your pants support directory
3. Configure pants.ini
4. Add new rules
5. Add plugins to extend beyond the default ruleset
6. Blacklisting

## Configuring pants.ini

[lint.javascriptstyle]
javascriptstyle_dir: %(pants_supportdir)s/javascriptstyle
skip: False
fail_slow: False

[fmt.javascriptstyle]
javascriptstyle_dir: %(pants_supportdir)s/javascriptstyle
skip: False
fail_slow: False


## Adding new rules

Add new rules to the .eslintrc file under the "rules" section.
A full list of eslint rules can be found at http://eslint.org/docs/rules

For plugins, you will need to append the plugin name followed by a '/'.

"react/jsx-indent": [2, 2]


## Adding new plugins

New plugins will need to be installed in the package.json and added to the .eslintrc

To add react plugin to package.json:

yarn add eslint-plugin-react

To add react plugin to .eslintrc:

"plugins": [
"react"
],


## Blacklisting

You can blacklist files to be excluded from the style checker by listing them in exclude.js.

The blacklist supports glob/rglob through the use of \*/\*\* syntax. See default.

By default the paths:

- node_modules/\*\*
- *\.min.js
- bundle.js
- coverage/\*\*
- hidden files/folders (beginning with .)

and all patterns in a project's root .gitignore file are automatically ignored.
4 changes: 4 additions & 0 deletions build-support/javascriptstyle/bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env node

const opts = require('../options.js');
require('standard-engine').cli(opts);
12 changes: 12 additions & 0 deletions build-support/javascriptstyle/exclude.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
files: [
"contrib/node/examples/3rdparty",
"contrib/node/examples/src/node/preinstalled-project",
"contrib/node/examples/src/node/server-project",
"contrib/node/examples/src/node/web-build-tool",
"contrib/node/examples/src/node/web-component-button",
"contrib/node/examples/src/node/web-dependency-test",
"contrib/node/examples/src/node/web-project",
"contrib/node/tests"
]
};
6 changes: 6 additions & 0 deletions build-support/javascriptstyle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// programmatic usage
const Linter = require('standard-engine').linter;

const opts = require('./options.js');

module.exports = new Linter(opts);
24 changes: 24 additions & 0 deletions build-support/javascriptstyle/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const eslint = require('eslint');
const path = require('path');
const pkg = require('./package.json');
const exclude = require('./exclude.js');

// Option configuration for standard-engine
// See https://github.com/standard/standard-engine for more details.
module.exports = {
cmd: 'javascriptstyle', // should match the "bin" key in your package.json
version: pkg.version,
homepage: pkg.homepage,
bugs: pkg.bugs.url,
tagline: 'Pants JavaScript Standard Style',
eslint: eslint,
eslintConfig: {
configFile: path.join(__dirname, '.eslintrc')
},
parseOpts: function (opts, packageOpts, rootDir) {
// Ignore the excluded files
opts.ignore.push.apply(opts.ignore, exclude.files)
return opts
},
cwd: '' // current working directory, passed to eslint
};
28 changes: 28 additions & 0 deletions build-support/javascriptstyle/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "javascriptstyle",
"version": "1.0.0",
"description": "Pants JavaScript Standard Style",
"main": "index.js",
"homepage": "https://github.com/pantsbuild/pants",
"license": "MIT",
"bin": {
"javascriptstyle": "./bin/cli.js"
},
"scripts": {
"test": "node ./bin/cli.js && tape test/*.js",
"test-quick": "node ./bin/cli.js"
},
"dependencies": {
"babel-eslint": "^7.2.3",
"eslint": "^4.3.0",
"standard-engine": "^7.1.0",
"tape": "^4.8.0"
},
"bugs": {
"url": "https://github.com/pantsbuild/pants/issues"
},

"javascriptstyle": {
"ignore": []
}
}
20 changes: 20 additions & 0 deletions build-support/javascriptstyle/test/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const javascriptstyle = require('../');
const test = require('tape');

test('api: lintFiles', function (t) {
t.plan(3);
javascriptstyle.lintFiles([], { cwd: 'bin' }, function (err, result) {
t.error(err, 'no error while linting');
t.equal(typeof result, 'object', 'result is an object');
t.equal(result.errorCount, 0);
});
});

test('api: lintText', function (t) {
t.plan(3);
javascriptstyle.lintText('console.log("hi there");\n', function (err, result) {
t.error(err, 'no error while linting');
t.equal(typeof result, 'object', 'result is an object');
t.equal(result.errorCount, 1, 'should have used single quotes');
});
});
Loading