Skip to content

Commit e4be931

Browse files
committed
feat: add configurable options (#3)
* feature: add configurable options * refactor: refactor parse code * refactor: refactor all tests * test: add tests for options * chore: update build script to copy json files * doc: add configuration to readme
1 parent 0e9b766 commit e4be931

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2069
-1881
lines changed

.babelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"presets": [["@babel/preset-env", { "targets": ["last 2 versions"] }]]
2+
"presets": [["@babel/preset-env", { "targets": ["last 2 versions"] }]],
3+
"ignore": ["./test/mocks/"]
34
}

.eslintignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
coverage
1+
coverage
2+
test/mocks/babel
3+
test/mocks/flow

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ coverage
88
node_modules
99

1010
#build
11-
index.js
11+
dist
1212

1313
report*

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,13 @@ Install prettier-plugin-tailwind-css:
5454
```
5555
npm install --save-dev prettier-plugin-tailwind-css
5656
```
57+
58+
## Configuration
59+
60+
Prettier for Tailwind supports the following options.
61+
62+
| Name | Default | Description |
63+
| ------------------------- | ------------------- | --------------------------------------------------------------------------------------------------- |
64+
| `removeDuplicatesClasses` | `true` | If set to `"true"`, all duplicate classes found will be deleted |
65+
| `classRegex` | `./src/regex.json` | See [file](https://raw.githubusercontent.com/marcosvega91/prettier-tailwind/master/src/regex.json) |
66+
| `classSorter` | `./src/sorter.json` | See [file](https://raw.githubusercontent.com/marcosvega91/prettier-tailwind/master/src/sorter.json) |

jest.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ module.exports = {
44
testMatch: ['<rootDir>/test/**/*.js'],
55
moduleFileExtensions: ['js'],
66
collectCoverage: false,
7-
collectCoverageFrom: ['src/**/*.js']
7+
collectCoverageFrom: ['src/**/*.js'],
8+
transformIgnorePatterns: ['<rootDir>/test/mocks'],
9+
testPathIgnorePatterns: ['<rootDir>/test/mocks']
810
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "prettier-plugin-tailwind-css",
33
"version": "0.0.5-development",
4-
"main": "index.js",
4+
"main": "dist/index.js",
55
"license": "MIT",
66
"scripts": {
77
"build": "./node_modules/.bin/rollup -c",
@@ -31,6 +31,7 @@
3131
"jest": "^26.1.0",
3232
"lint-staged": "^10.2.11",
3333
"rollup": "^2.21.0",
34+
"rollup-plugin-copy": "^3.3.0",
3435
"semantic-release": "^17.1.1"
3536
},
3637
"husky": {

rollup.config.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import babel from '@rollup/plugin-babel'
2+
import copy from 'rollup-plugin-copy'
23

34
export default {
45
external: ['prettier/parser-html', 'prettier/parser-flow', 'prettier/parser-babel'],
56
input: 'src/index.js',
67
output: {
7-
file: './index.js',
8+
file: './dist/index.js',
89
format: 'cjs'
910
},
1011
sourceMap: 'inline',
1112
plugins: [
13+
copy({
14+
targets: [
15+
{ src: 'src/sorter.json', dest: 'dist/' },
16+
{ src: 'src/regex.json', dest: 'dist/' }
17+
]
18+
}),
1219
babel({
1320
exclude: 'node_modules/**',
1421
presets: [['@babel/preset-env', { modules: false }]]

src/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import prettierParserHTML from 'prettier/parser-html'
22
import prettierParserFlow from 'prettier/parser-flow'
33
import prettierParserBabel from 'prettier/parser-babel'
4-
import parserHtml from './parsers/parserHtml'
5-
import parserJSX from './parsers/parserJSX'
4+
import { getParse } from './parser'
5+
import { options } from './options'
66

77
const languages = [
88
{
@@ -19,19 +19,21 @@ const languages = [
1919
const parsers = {
2020
html: {
2121
...prettierParserHTML.parsers.html,
22-
parse: parserHtml.parse
22+
parse: getParse('html', prettierParserHTML.parsers.html.parse)
2323
},
2424
flow: {
2525
...prettierParserFlow.parsers.flow,
26-
parse: parserJSX.parse
26+
parse: getParse('javascriptreact', prettierParserFlow.parsers.flow.parse)
2727
},
2828
babel: {
2929
...prettierParserBabel.parsers.babel,
30-
parse: parserJSX.parse
30+
parse: getParse('javascriptreact', prettierParserBabel.parsers.babel.parse)
3131
}
3232
}
3333

34-
module.exports = {
34+
const plugin = {
3535
languages,
36-
parsers
36+
parsers,
37+
options
3738
}
39+
export default plugin

0 commit comments

Comments
 (0)