-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 77a4f09
Showing
10 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
package-lock.json | ||
npm-debug.log | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "node" | ||
notifications: | ||
email: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# fake-tag changelog | ||
|
||
## 0.1.0 | ||
|
||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = function() { | ||
var tagArgs = arguments | ||
return tagArgs[0].reduce(function(accumulator, string, index) { | ||
accumulator += string | ||
if (index + 1 in tagArgs) accumulator += tagArgs[index + 1] | ||
return accumulator | ||
}, '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
{ | ||
"name": "fake-tag", | ||
"version": "1.0.0", | ||
"description": "A fake template literal tag to trick linters and formatters into action.", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Jayden Seric", | ||
"email": "[email protected]", | ||
"url": "https://jaydenseric.com" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jaydenseric/fake-tag.git" | ||
}, | ||
"homepage": "https://github.com/jaydenseric/fake-tag#readme", | ||
"bugs": "https://github.com/jaydenseric/fake-tag/issues", | ||
"keywords": [ | ||
"es6", | ||
"dummy", | ||
"fake", | ||
"template", | ||
"literal", | ||
"string", | ||
"tag" | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.0.0-beta.4", | ||
"eslint": "^4.19.1", | ||
"eslint-plugin-ava": "^4.5.1", | ||
"eslint-plugin-prettier": "^2.5.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.0.4", | ||
"prettier": "^1.12.1" | ||
}, | ||
"scripts": { | ||
"lint": "eslint . --fix && prettier '**/*.{json,md}' --write", | ||
"test": "ava", | ||
"watch": "ava -w", | ||
"precommit": "lint-staged", | ||
"prepublishOnly": "npm run lint && npm test" | ||
}, | ||
"lint-staged": { | ||
"*.js": "eslint", | ||
"*.{json,md}": "prettier -l" | ||
}, | ||
"eslintConfig": { | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"browser": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:ava/recommended" | ||
], | ||
"plugins": [ | ||
"ava", | ||
"prettier" | ||
], | ||
"rules": { | ||
"curly": [ | ||
"error", | ||
"multi" | ||
], | ||
"prettier/prettier": "error" | ||
} | ||
}, | ||
"prettier": { | ||
"proseWrap": "never", | ||
"singleQuote": true, | ||
"semi": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# fake-tag | ||
|
||
[![npm version](https://img.shields.io/npm/v/fake-tag.svg)](https://npm.im/fake-tag) ![Licence](https://img.shields.io/npm/l/fake-tag.svg) [![Github issues](https://img.shields.io/github/issues/jaydenseric/fake-tag.svg)](https://github.com/jaydenseric/fake-tag/issues) [![Github stars](https://img.shields.io/github/stars/jaydenseric/fake-tag.svg)](https://github.com/jaydenseric/fake-tag/stargazers) [![Travis status](https://img.shields.io/travis/jaydenseric/fake-tag.svg)](https://travis-ci.org/jaydenseric/fake-tag) | ||
|
||
A fake template literal tag to trick linters and formatters into action. Interpolations and escapes are tested. | ||
|
||
This hack will be redundant once comment tags are supported by tools [such as Prettier](https://github.com/prettier/prettier/issues/4360): | ||
|
||
<!-- prettier-ignore --> | ||
```js | ||
/* GraphQL */` | ||
{ | ||
foo | ||
} | ||
` | ||
``` | ||
|
||
## Install | ||
|
||
Install with [npm](https://npmjs.com): | ||
|
||
```sh | ||
npm install fake-tag | ||
``` | ||
|
||
## Usage | ||
|
||
Import and use the tag with the required name: | ||
|
||
```js | ||
import gql from 'fake-tag' | ||
|
||
const typeDefs = gql` | ||
"A foo." | ||
type Foo { | ||
"The \`Foo\` ID." | ||
id: ID! | ||
} | ||
` | ||
``` | ||
|
||
## Why not `String.raw`? | ||
|
||
It doesn’t unescape characters. For the usage example, if you `console.log(typeDefs)` before and after replacing the import with`const gql = String.raw` you will see the difference in the type description markdown: | ||
|
||
```diff | ||
"A foo." | ||
type Foo { | ||
- "The `Foo` ID." | ||
+ "The \`Foo\` ID." | ||
id: ID! | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import test from 'ava' | ||
import tag from '.' | ||
|
||
test('Empty.', t => { | ||
t.is(tag``, '') | ||
}) | ||
|
||
test('Escapes.', t => { | ||
t.is(tag`\``, '`') | ||
}) | ||
|
||
test('No variables.', t => { | ||
t.is(tag`1`, '1') | ||
}) | ||
|
||
test('Only variables.', t => { | ||
t.is(tag`${1}${2}${3}`, '123') | ||
}) | ||
|
||
test('Surrounding variables.', t => { | ||
t.is(tag`${1}2${3}`, '123') | ||
}) | ||
|
||
test('Surrounded variables.', t => { | ||
t.is(tag`1${2}${3}4`, '1234') | ||
}) |