Skip to content

Commit

Permalink
Added eslint config for package; linted package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Edwards committed Jun 18, 2021
1 parent 6e11bbd commit 65abc7b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 38 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
**/packages/@glimmerx/babel-preset/test/**/output.js
**/packages/@glimmerx/babel-preset/test/**/code.ts
**/packages/@glimmerx/babel-preset/test/**/output.ts
**/packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/**/code.js
**/packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/**/output.js
**/packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/**/code.gjs
**/packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/**/output.gjs
**/packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/**/code.ts
**/packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/**/output.ts
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ module.exports = {
files: [
'packages/@glimmerx/babel-preset/**/*.js',
'packages/@glimmerx/eslint-plugin/**/*.js',
'packages/@glimmerx/prettier-plugin-component-templates/**/*.js',
'packages/@glimmerx/webpack-loader/**/*.js',
'packages/@glimmerx/prettier-plugin-component-templates/test/index.js',
],
env: {
es6: true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"problems": "tsc -p tsconfig.json --noEmit",
"start": "webpack-dev-server",
"storybook": "yarn build && yarn workspace basic-example-app storybook",
"test": "yarn lint && testem ci && yarn test:babel-plugins",
"test": "yarn lint && testem ci && yarn test:babel-plugins && yarn test:prettier",
"test:babel-plugins": "mocha -r esm --timeout 5000 packages/@glimmerx/babel-preset/test packages/@glimmerx/eslint-plugin/test/lib/rules",
"test:ember": "yarn workspace basic-addon ember try:one",
"test:prettier": "mocha packages/@glimmerx/prettier-plugin-component-templates/test",
"test:prettier": "mocha -r esm packages/@glimmerx/prettier-plugin-component-templates/test",
"test:playground": "yarn workspace glimmerx-playground test",
"test:watch": "testem"
},
Expand Down
60 changes: 29 additions & 31 deletions packages/@glimmerx/prettier-plugin-component-templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function formatHbs(path, print, textToDoc, options) {

const text = node.quasis
.map((quasi, index, quasis) =>
index === quasis.length - 1 ? quasi.value.raw : quasi.value.raw + placeholders[index]
)
index === quasis.length - 1 ? quasi.value.raw : quasi.value.raw + placeholders[index])
.join('');

const expressionDocs = path.map(print, 'expressions');
Expand All @@ -28,43 +27,42 @@ function formatHbs(path, print, textToDoc, options) {
return '``';
}

const contentDoc = mapDoc(
stripTrailingHardline(textToDoc(text, { parser: 'glimmer' })),
(doc) => {
const placeholderRegex = new RegExp(placeholderPattern, 'g');
const hasPlaceholder = typeof doc === 'string' && placeholderRegex.test(doc);
const contentDoc = mapDoc(stripTrailingHardline(textToDoc(text, { parser: 'glimmer' })), (
doc
) => {
const placeholderRegex = new RegExp(placeholderPattern, 'g');
const hasPlaceholder = typeof doc === 'string' && placeholderRegex.test(doc);

if (!hasPlaceholder) {
return doc;
}
if (!hasPlaceholder) {
return doc;
}

let parts = [];
let parts = [];

const components = doc.split(placeholderRegex);
for (let i = 0; i < components.length; i++) {
const component = components[i];
const components = doc.split(placeholderRegex);
for (let i = 0; i < components.length; i++) {
const component = components[i];

if (i % 2 === 0) {
if (component) {
parts.push(component);
}
continue;
if (i % 2 === 0) {
if (component) {
parts.push(component);
}

const placeholderIndex = +component;

parts.push(
concat([
'${',
group(concat([indent(concat([softline, expressionDocs[placeholderIndex]])), softline])),
'}',
])
);
continue;
}

return concat(parts);
const placeholderIndex = +component;

parts.push(
concat([
'${',
group(concat([indent(concat([softline, expressionDocs[placeholderIndex]])), softline])),
'}',
])
);
}
);

return concat(parts);
});

return group(concat(['`', indent(concat([hardline, group(contentDoc)])), softline, '`']));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lib/**/*"
],
"scripts": {
"test": "mocha"
"test": "mocha -r esm"
},
"devDependencies": {
"chai": "^4.3.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const fs = require('fs');
const prettier = require('prettier');
const path = require('path');
const expect = require('chai').expect;
import fs from 'fs';
import prettier from 'prettier';
import path from 'path';
import { expect } from 'chai';

describe('integration', function () {
let options = {
Expand Down

0 comments on commit 65abc7b

Please sign in to comment.