Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
refactor: spring cleanup
Browse files Browse the repository at this point in the history
Remove babel and convert code to use CommonJS format.
Convert rules to updated format (https://eslint.org/docs/developer-guide/working-with-rules).

closes #654
  • Loading branch information
dferber90 committed May 9, 2018
1 parent 7c0039d commit 59673dd
Show file tree
Hide file tree
Showing 58 changed files with 725 additions and 2,110 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules/**
coverage/**
dist/**
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ plugins:
rules:
prettier/prettier: ["error", {"trailingComma": "es5", "singleQuote": true}]
semi: ["error", "always"]
global-require: 0
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
coverage
dist
node_modules
npm-debug.log
.nyc_output
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ node_js:
- 4
- 10
before_install:
- npm i -g npm@^5.3.0
- npm i -g npm@^6.0.0
- npm -v
- npm i -g codeclimate-test-reporter
before_script:
- npm prune
script:
- npm run test
after_success:
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ npm install eslint-plugin-meteor --save-dev

## Configuration

Add these keys to your `.eslintrc.json` file:
Create an `.eslintrc.json` file with this content at the root of your project:

```json
{
Expand Down Expand Up @@ -79,7 +79,7 @@ An article with detailed setup instructions can be found [here](https://medium.c
This plugin exports a recommended configuration which enforces good Meteor practices.
The rules enabled in this configuration can be found in [`lib/index.js`](https://github.com/dferber90/eslint-plugin-meteor/blob/master/lib/index.js).

To enable the recommended configuration use the extends property in your `.eslintrc` config file:
To enable the recommended configuration use the extends property in your `.eslintrc.json` config file:

```json
{
Expand All @@ -90,6 +90,22 @@ To enable the recommended configuration use the extends property in your `.eslin
}
```

You probably also want to enable ESLint to parse ECMAScript 2015 and to support React templates.

Add the following to your `.eslintrc.json` config file

```json
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
}
}
```

See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.

## Limitations
Expand Down
27 changes: 17 additions & 10 deletions docs/guides/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

This document describes how developers can contribute by adding rules for ESLint-plugin-Meteor. Before implementing a rule, create an issue to discuss the proposed rule. After getting some feedback, you can develop the rule. Every rule must have adequate tests and documentation. Reading the [ESLint developer guide](http://eslint.org/docs/developer-guide/) is a good start.


Run the following commands to set up ESLint-plugin-Meteor in development mode.

```bash
Expand All @@ -15,16 +14,25 @@ $ npm install

## Development Setup

This plugin uses ES2015 which is transpiled to ES5 by Babel. All files in `lib/` are transpiled to `dist/`.
This plugin runs untranspiled. The source code needs to be compatible with node version 4 and upwards.

Run `npm run` to see the available scripts for tests, unit-tests and so on.

```bash
# start transpiling continuously
$ npm run build:w
# run unit-tests only
$ npm run unit-test

# make some changes to the code
# run linter only
$ npm run lint

# run tests
# run unit-tests only
$ npm run unit-test

# run unit-tests in watch mode
$ npm run unit-test:watch

# run complete test suite
$ npm test
```

## Linking
Expand All @@ -33,6 +41,7 @@ npm can link packages. This makes version set up for development available in ot

```bash
# Make this package available globally
# by running this command from the root of this package
$ npm link

# In a project using this plugin, install the linked version
Expand All @@ -41,7 +50,6 @@ $ npm link eslint-plugin-meteor

Read more about linking [here](https://docs.npmjs.com/cli/link).


## Creating rules

Creating rules for ESLint-plugin-Meteor is best done by using the scaffolding tool.
Expand All @@ -55,16 +63,15 @@ This will scaffold all required files for the new rule. Add the implementation,
After implementation, the rule has to be exported from `lib/index.js`.
Recommended options for the rule should be set as well (also in `lib/index.js`).


## Give back

After making sure all tests pass and the test-coverage is at 100%, please send a PR to [dferber90/eslint-plugin-meteor](https://github.com/dferber90/eslint-plugin-meteor).
Git commits messages must follow the [conventional changelog](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines) format.

Git commits messages must follow the [conventional changelog](https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#-git-commit-guidelines) format. This is important as we're releasing automatically and the next version is determined upon the commit messages.

## Essential Development Resources

These specs and tools help enormously when developing new rules.

* [ESTree Spec](https://github.com/estree/estree/blob/master/spec.md)
* [Espree Parser](http://eslint.org/parser/)
* [JS AST Explorer](http://astexplorer.net/)
36 changes: 19 additions & 17 deletions docs/guides/setup.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Setup Guide

This document describes how to set up ESLint and ESLint-plugin-Meteor in Meteor projects.
*It must have steps for Meteor projects before 1.3 and with 1.3.*
*It should further show how to use only selected rules (or link to the page of the ESLint documentation)*

_It must have steps for Meteor projects before 1.3 and with 1.3._
_It should further show how to use only selected rules (or link to the page of the ESLint documentation)_

This guide assumes you have [npm](https://www.npmjs.com/) installed.

## Setup

If you don't have a `package.json` at the root of your Meteor project, create one with `npm init --yes`. Next, add `private: true` to your package (to avoid some warnings and prevent publishing your project to npm's registry accidentally).

Now, install ESLint and ESLint-plugin-Meteor as development dependencies:
Expand All @@ -23,19 +23,20 @@ A minimal configuration should look like this:

```json
{
"plugins": [
"meteor"
],
"extends": [
"plugin:meteor/recommended"
]
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"plugins": ["meteor"],
"extends": ["plugin:meteor/recommended"]
}
```


And that's it 🎉!


More information on setting up ESLint can be found [here](http://eslint.org/docs/user-guide/configuring).

An article with detailed setup instructions specifically for Meteor projects can be found [here](https://medium.com/@dferber90/linting-meteor-8f229ebc7942).
Expand All @@ -44,8 +45,8 @@ An article with detailed setup instructions specifically for Meteor projects can

Here are some more tips to further improve the setup.


### Add environments

An environment tells ESLint about defined globals.
Since Meteor code can run in the browser and on the server, it's wise to add `browser` and `node`. As Meteor supports ES2015, `es6` should be added as well. And of course the `meteor` environment itself. Since Meteor 1.3 applications can use modules, they should be enabled for ESLint as well.

Expand All @@ -66,8 +67,8 @@ Since Meteor code can run in the browser and on the server, it's wise to add `br
}
```


### Collections and globals

ESLint needs to know about globals defined in your application.
Add the globals key to `.eslintrc.json`:

Expand All @@ -84,19 +85,20 @@ Add the globals key to `.eslintrc.json`:

Here, you can define all globals your application uses. This is also the place to add globals provided through packages from Atmosphere. The boolean values tell ESLint whether it is okay for your application code to overwrite these globals (`true`) or not (`false`).


### Usage with React

If you are using React, you should:
- enable JSX syntax (see: [ESLint configuration documentation](http://eslint.org/docs/user-guide/configuring#specifying-parser-options))
- use ESLint-plugin-React (see: [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react))

* enable JSX syntax (see: [ESLint configuration documentation](http://eslint.org/docs/user-guide/configuring#specifying-parser-options))
* use ESLint-plugin-React (see: [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react))

## ESLint-config-airbnb

Use a rule preset like [eslint-config-airbnb](https://www.npmjs.com/package/eslint-config-airbnb).
It has lots of well-thought-out rules.


### Using YAML instead

ESLint supports different formats in which the configuration can be specified.
If `.eslintrc.json` is renamed to `.eslint.yaml` then the full configuration can be written like this:

Expand Down
76 changes: 35 additions & 41 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
import auditArgumentChecks from './rules/audit-argument-checks';
import noSession from './rules/no-session';
import noBlazeLifecycleAssignment from './rules/no-template-lifecycle-assignments';
import noZeroTimeout from './rules/no-zero-timeout';
import eventmapParams from './rules/eventmap-params';
import prefixEventmapSelectors from './rules/prefix-eventmap-selectors';
import preferSessionEquals from './rules/prefer-session-equals';
import templateNamingConvention from './rules/template-names';
import scopeDomLookups from './rules/scope-dom-lookups';
import noDomLookupOnCreated from './rules/no-dom-lookup-on-created';
import noTemplateParentData from './rules/no-template-parent-data';

export const rules = {
'audit-argument-checks': auditArgumentChecks,
'no-session': noSession,
'no-template-lifecycle-assignments': noBlazeLifecycleAssignment,
'no-zero-timeout': noZeroTimeout,
'eventmap-params': eventmapParams,
'prefix-eventmap-selectors': prefixEventmapSelectors,
'prefer-session-equals': preferSessionEquals,
'template-names': templateNamingConvention,
'scope-dom-lookups': scopeDomLookups,
'no-dom-lookup-on-created': noDomLookupOnCreated,
'no-template-parent-data': noTemplateParentData,
const allRules = {
'audit-argument-checks': require('./rules/audit-argument-checks'),
'no-session': require('./rules/no-session'),
'no-template-lifecycle-assignments': require('./rules/no-template-lifecycle-assignments'),
'no-zero-timeout': require('./rules/no-zero-timeout'),
'eventmap-params': require('./rules/eventmap-params'),
'prefix-eventmap-selectors': require('./rules/prefix-eventmap-selectors'),
'prefer-session-equals': require('./rules/prefer-session-equals'),
'template-names': require('./rules/template-names'),
'scope-dom-lookups': require('./rules/scope-dom-lookups'),
'no-dom-lookup-on-created': require('./rules/no-dom-lookup-on-created'),
'no-template-parent-data': require('./rules/no-template-parent-data'),
};

export const configs = {
recommended: {
rules: {
'meteor/audit-argument-checks': 2,
'meteor/no-session': 2,
'meteor/no-template-lifecycle-assignments': 2,
'meteor/no-zero-timeout': 2,
'meteor/eventmap-params': 2,
'meteor/prefix-eventmap-selectors': 0,
'meteor/prefer-session-equals': 0,
'meteor/template-names': 2,
'meteor/scope-dom-lookups': 0,
'meteor/no-dom-lookup-on-created': 0,
'meteor/no-template-parent-data': 0,
module.exports = {
rules: allRules,
configs: {
recommended: {
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
ecmaFeatures: { jsx: true },
},
plugins: ['meteor'],
rules: {
'meteor/audit-argument-checks': 2,
'meteor/no-session': 2,
'meteor/no-template-lifecycle-assignments': 2,
'meteor/no-zero-timeout': 2,
'meteor/eventmap-params': 2,
'meteor/prefix-eventmap-selectors': 0,
'meteor/prefer-session-equals': 0,
'meteor/template-names': 2,
'meteor/scope-dom-lookups': 0,
'meteor/no-dom-lookup-on-created': 0,
'meteor/no-template-parent-data': 0,
},
},
},
guide: {
rules: {},
},
};
Loading

0 comments on commit 59673dd

Please sign in to comment.