Skip to content

Commit

Permalink
feat(defaultOptions): set scope to false by default
Browse files Browse the repository at this point in the history
scope conceptually is a good idea, but has too many variations. I want to find a good way to support it, potentially by capping the depth. This still runs into issues with other plugins.

This can still be turned on via a flag. Please open an issue if you wish to have this back by default.
  • Loading branch information
kwelch committed Jul 26, 2017
1 parent e87b72f commit 0f66e90
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 64 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"doc",
"test"
]
},
{
"login": "mqklin",
"name": "Maksim",
"avatar_url": "https://avatars1.githubusercontent.com/u/9456433?v=4",
"profile": "https://github.com/mqklin",
"contributions": [
"bug"
]
}
]
}
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,32 @@
[![codecov](https://codecov.io/gh/kwelch/babel-plugin-captains-log/branch/master/graph/badge.svg?style=flat-square)](https://codecov.io/gh/kwelch/babel-plugin-captains-log)

[![MIT License](https://img.shields.io/npm/l/kwelch.svg?style=flat-square)](http://opensource.org/licenses/MIT)
[![Roadmap](https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square)]([roadmap])
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-2-orange.svg?style=flat-square)](#contributors)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)

[![Watch on GitHub](https://img.shields.io/github/watchers/kwelch/babel-plugin-captains-log.svg?style=social)](https://github.com/kwelch/babel-plugin-captains-log/watchers)
[![Star on GitHub](https://img.shields.io/github/stars/kwelch/babel-plugin-captains-log.svg?style=social)](https://github.com/kwelch/babel-plugin-captains-log/stargazers)
[![Tweet](https://img.shields.io/twitter/url/https/github.com/kwelch/babel-plugin-captains-log.svg?style=social)](https://twitter.com/intent/tweet?text=Check%20out%20babel-plugin-captains-log!%20https://github.com/kwelch/babel-plugin-captains-log%20%F0%9F%91%8D)
[![Join the chat at https://gitter.im/babel-plugin-captains-log/Lobby](https://badges.gitter.im/babel-plugin-captains-log/Lobby.svg?style=flat-square)](https://gitter.im/babel-plugin-captains-log/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

## Usage

`babel-plugin-captains-log` injects helpful details into console statements.

Default bahavior:
- Prepend console statement scope
- prepend console statement file & location
- add inject variable name into console statements

**Transforms**
```diff
function add(a, b) {
- console.log(a, b);
+ console.log("simple.js(2:2)", "add:", "a", a, "b", b);
+ console.log("simple.js(2:2)", "a", a, "b", b);
return a + b;
}

const subtract = (a, b) => {
- console.log(a, b);
+ console.info("simple.js(7:2)", "subtract:", "a", a, "b", b);
+ console.info("simple.js(7:2)", "a", a, "b", b);
return a - b;
};
```
Expand Down Expand Up @@ -108,36 +106,34 @@ Flags are values set for all methods and are used to turn that feature on or off
}
```

#### Inject Scope
#### Inject File Name
**Default**: `true`

```
{
plugins: [
["captains-log", {
"injectScope": true
"injectFileName": true
}]
]
}
```

#### Inject File Name
**Default**: `true`
#### Inject Scope _(Experimental)_
_This has a few issues with other plugins particularly react-hot-loader, as it changes method names. Also, it was written for recursion which adds too much noise to the console statement which is against this libraries purpose_

**Default**: `false`

```
{
plugins: [
["captains-log", {
"injectFileName": true
"injectScope": true
}]
]
}
```

## Roadmap

- [ ] Add ability to timestamp console statements

## License

MIT
Expand All @@ -147,8 +143,8 @@ MIT
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars0.githubusercontent.com/u/1295580?v=3" width="100px;"/><br /><sub>Kyle Welch</sub>](http://www.krwelch.com)<br />[💻](https://github.com/kwelch/babel-plugin-captains-log/commits?author=kwelch "Code") [📖](https://github.com/kwelch/babel-plugin-captains-log/commits?author=kwelch "Documentation") [⚠️](https://github.com/kwelch/babel-plugin-captains-log/commits?author=kwelch "Tests") |
| :---: |
| [<img src="https://avatars0.githubusercontent.com/u/1295580?v=3" width="100px;"/><br /><sub>Kyle Welch</sub>](http://www.krwelch.com)<br />[💻](https://github.com/kwelch/babel-plugin-captains-log/commits?author=kwelch "Code") [📖](https://github.com/kwelch/babel-plugin-captains-log/commits?author=kwelch "Documentation") [⚠️](https://github.com/kwelch/babel-plugin-captains-log/commits?author=kwelch "Tests") | [<img src="https://avatars1.githubusercontent.com/u/9456433?v=4" width="100px;"/><br /><sub>Maksim</sub>](https://github.com/mqklin)<br />[🐛](https://github.com/kwelch/babel-plugin-captains-log/issues?q=author%3Amqklin "Bug reports") |
| :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
Expand Down
30 changes: 15 additions & 15 deletions src/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function add(a, b) {
↓ ↓ ↓ ↓ ↓ ↓
function add(a, b) {
console.log(\\"unknown(2:2)\\", \\"add:\\", \\"a\\", a, \\"b\\", b);
console.log(\\"unknown(2:2)\\", \\"a\\", a, \\"b\\", b);
return a + b;
}
"
Expand All @@ -36,7 +36,7 @@ const subtract = (a, b) => {
↓ ↓ ↓ ↓ ↓ ↓
const subtract = (a, b) => {
console.info(\\"unknown(2:2)\\", \\"subtract:\\", \\"a\\", a, \\"b\\", b);
console.info(\\"unknown(2:2)\\", \\"a\\", a, \\"b\\", b);
return a - b;
};
"
Expand All @@ -53,7 +53,7 @@ multiple = () => {
let multiply;
multiple = () => {
console.log(\\"unknown(3:2)\\", \\"multiple:\\", \\"3\\");
console.log(\\"unknown(3:2)\\", \\"3\\");
};
"
`;
Expand All @@ -69,7 +69,7 @@ divide = function() {
let divide;
divide = function () {
console.log(\\"unknown(3:2)\\", \\"divide:\\", \\"4\\");
console.log(\\"unknown(3:2)\\", \\"4\\");
};
"
`;
Expand All @@ -83,7 +83,7 @@ const power = function pow() {
↓ ↓ ↓ ↓ ↓ ↓
const power = function pow() {
console.log(\\"unknown(2:2)\\", \\"power:\\", 5);
console.log(\\"unknown(2:2)\\", 5);
};
"
`;
Expand All @@ -106,13 +106,13 @@ const obj = {
const obj = {
method1: function () {
console.log(\\"unknown(3:4)\\", \\"obj.method1:\\", 6);
console.log(\\"unknown(3:4)\\", 6);
},
method2: () => {
console.log(\\"unknown(6:4)\\", \\"obj.method2:\\", 7);
console.log(\\"unknown(6:4)\\", 7);
},
method3() {
console.log(\\"unknown(9:4)\\", \\"obj.method3:\\", 8);
console.log(\\"unknown(9:4)\\", 8);
}
};
"
Expand Down Expand Up @@ -140,16 +140,16 @@ const Component = () => {
const Component = () => {
const privateMethod = () => {
console.log(\\"unknown(3:4)\\", \\"Component.privateMethod:\\", 1);
console.log(\\"unknown(3:4)\\", 1);
};
return class HighOrderComponent {
showList() {
arr.map(i => {
console.log(\\"unknown(8:8)\\", \\"Component.HighOrderComponent.showList:\\", \\"i\\", i);
console.log(\\"unknown(8:8)\\", \\"i\\", i);
});
}
render() {
console.log(\\"unknown(12:6)\\", \\"Component.HighOrderComponent.render:\\", 2);
console.log(\\"unknown(12:6)\\", 2);
}
};
};
Expand All @@ -168,7 +168,7 @@ class ToDoComponent {
class ToDoComponent {
render() {
console.log(\\"unknown(3:4)\\", \\"ToDoComponent.render:\\", this.props);
console.log(\\"unknown(3:4)\\", this.props);
}
}
"
Expand Down Expand Up @@ -205,16 +205,16 @@ function logAll() {
console.assert(1 === 1);
console.clear();
console.count(\\"count\\");
console.debug(\\"unknown(5:2)\\", \\"logAll:\\", \\"debug\\");
console.debug(\\"unknown(5:2)\\", \\"debug\\");
console.dir(obj);
console.error(\\"error\\");
console.exception(\\"exception\\");
console.group(\\"group\\");
console.groupEnd(\\"group\\");
console.groupCollapsed(\\"groupCollapsed\\");
console.groupEnd(\\"groupCollapsed\\");
console.info(\\"unknown(13:2)\\", \\"logAll:\\", \\"info\\");
console.log(\\"unknown(14:2)\\", \\"logAll:\\", \\"log\\");
console.info(\\"unknown(13:2)\\", \\"info\\");
console.log(\\"unknown(14:2)\\", \\"log\\");
console.profile(\\"profile\\");
console.profileEnd(\\"profile\\");
console.table([\\"table\\"]);
Expand Down
Loading

0 comments on commit 0f66e90

Please sign in to comment.