Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting for the ember-scoped-css package #23

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ember-scoped-css/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# unconventional js
/blueprints/*/files/

# compiled output
/dist/

# misc
/coverage/
37 changes: 37 additions & 0 deletions ember-scoped-css/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
ecmaFeatures: {
modules: true,
},
},
plugins: ['node'],
extends: [
'eslint:recommended',
'plugin:node/recommended-module'
],
env: {
browser: false,
node: true,
},
rules: {
},
overrides: [
{
files: [
'./test/**/*.js',
],
env: {
mocha: true,
},
rules: {
'node/no-unpublished-import': 0,
}
},
],
};
6 changes: 5 additions & 1 deletion ember-scoped-css/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"scripts": {
"prepare": "npm run esbuild",
"test": "mocha",
"lint": "",
"lint": "eslint .",
"esbuild": "esbuild src/app-css-loader.js src/app-dependency-loader.js --bundle --outdir=dist --platform=node --out-extension:.js=.cjs"
},
"keywords": [],
Expand All @@ -40,9 +40,13 @@
"rollup": "^2.67.0",
"unplugin": "^1.0.1"
},
"peerDependencies": {
"webpack": "^5.0.0"
},
"devDependencies": {
"chai": "^4.3.7",
"esbuild": "^0.17.17",
"eslint": "^8.38.0",
"mocha": "^10.2.0",
"sinon": "^15.0.1",
"webpack": "^5.75.0"
Expand Down
6 changes: 0 additions & 6 deletions ember-scoped-css/src/addon-css-rollup.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import path from 'path';
import getPostfix from './getPostfix.js';
import rewriteCss from './rewriteCss.js';
import { readFile } from 'fs/promises';
import fsExists from './fsExists.js';
import findCssInJs from './findCssInJs.js';
import getImportedCssFiles from './getImportedCssFiles.js';
import recast from 'recast';

export default function () {
return {
Expand Down
2 changes: 1 addition & 1 deletion ember-scoped-css/src/addon-hbs-rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import getClassesTagsFromCss from './getClassesTagsFromCss.js';
import rewriteHbs from './rewriteHbs.js';
import fsExists from './fsExists.js';

export default function rollupCssColocation(options = {}) {
export default function rollupCssColocation() {
return {
name: 'addon-hbs-rollup',

Expand Down
2 changes: 1 addition & 1 deletion ember-scoped-css/src/addon-js-unplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import fsExists from './fsExists.js';
import findCssInJs from './findCssInJs.js';
import recast from 'recast';

export default createUnplugin((options) => {
export default createUnplugin(() => {
return {
name: 'addon-js-unplugin',

Expand Down
9 changes: 4 additions & 5 deletions ember-scoped-css/src/app-css-livereload-loader.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createUnplugin } from 'unplugin';
import path from 'path';
import { readFile, writeFile } from 'fs/promises';
import { readFile } from 'fs/promises';
import { Compilation } from 'webpack';
import getPostfix from './getPostfix.js';
import cheerio from 'cheerio';

export default createUnplugin(({ appDir, loaders, htmlEntrypointInfo }) => {
export default createUnplugin(({ loaders, htmlEntrypointInfo }) => {
return {
name: 'app-css-livereload-loader',

Expand Down Expand Up @@ -77,7 +76,7 @@ export default createUnplugin(({ appDir, loaders, htmlEntrypointInfo }) => {
if (!cssAssets.length) {
return;
}
let linkAdded = false;
// let linkAdded = false;
const document =
htmlEntrypointInfo.htmlEntryPoint.dom.window.document;

Expand All @@ -92,7 +91,7 @@ export default createUnplugin(({ appDir, loaders, htmlEntrypointInfo }) => {
link.rel = 'stylesheet';
link.href = '/' + asset;
head.appendChild(link);
linkAdded = true;
// linkAdded = true;
}
}

Expand Down
2 changes: 1 addition & 1 deletion ember-scoped-css/src/app-css-loader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import { createUnplugin } from 'unplugin';
import { basename, join } from 'path';
import { basename } from 'path';
import fsExists from './fsExists.js';
import getPostfix from './getPostfix.js';
import rewriteCss from './rewriteCss.js';
Expand Down
6 changes: 0 additions & 6 deletions ember-scoped-css/src/app-css-unplugin.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import { createUnplugin } from 'unplugin';
import replaceGlimmerAst from './replaceGlimmerAst.js';
import path from 'path';
import getPostfix from './getPostfix.js';
import getClassesTagsFromCss from './getClassesTagsFromCss.js';
import { readFile } from 'fs/promises';
import fsExists from './fsExists.js';

export default createUnplugin(() => {
return {
Expand Down
5 changes: 0 additions & 5 deletions ember-scoped-css/src/app-js-unplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import replaceGlimmerAst from './replaceGlimmerAst.js';
import path from 'path';
import getPostfix from './getPostfix.js';
import getClassesTagsFromCss from './getClassesTagsFromCss.js';
import { readFile } from 'fs/promises';
import fsExists from './fsExists.js';

function* iterateOpcodes(opcodes) {
for (let instruction of opcodes) {
Expand Down Expand Up @@ -50,14 +48,11 @@ export default createUnplugin(({ appDir }) => {

async transform(code, id) {
const cssPath = id.replace(/(\.js)|(\.hbs)/, '.css');
const cssFileName = path.basename(cssPath);
const postfix = getPostfix(cssPath);

return await replaceGlimmerAst(code, id, (opcodes, css) => {
const { classes, tags } = getClassesTagsFromCss(css);
const a = code;
// this.addWatchFile(cssPath);
const tmp = this;
const insertions = [];

for (let instruction of iterateOpcodes(opcodes[0])) {
Expand Down
2 changes: 0 additions & 2 deletions ember-scoped-css/src/babel-plugin-scoped-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const scopedClass = () => {
visitor: {
CallExpression(path, state) {
if (path.node?.callee?.name === 'precompileTemplate') {
let source = '';
if (path.node.arguments[0].type === 'StringLiteral') {
source = path.node.arguments[0].value;
path.node.arguments[0].value = replaceScopedClass(
path.node.arguments[0].value,
state.filename,
Expand Down
4 changes: 2 additions & 2 deletions ember-scoped-css/src/replaceScopedClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import recast from 'ember-template-recast';
import renameClass from './renameClass.js';
import getPostfix from './getPostfix.js';

export default function (hbs, templatePath, basePath) {
export default function (hbs, templatePath) {
let ast = recast.parse(hbs);
let stack = [];
const cssPath = templatePath.replace(/(\.hbs)?\.js$/, '.css');
Expand All @@ -13,7 +13,7 @@ export default function (hbs, templatePath, basePath) {
enter(node) {
stack.push(node);
},
exit(node) {
exit() {
stack.pop();
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function resolutionFor(originalId) {
}

async function preprocessTemplates(id) {
// eslint-disable-next-line node/no-unsupported-features/es-syntax
let ember = (await import('ember-source')).default;
let contents = await fs.readFile(id, 'utf-8');

Expand Down
1 change: 0 additions & 1 deletion ember-scoped-css/test/getPostfix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { stub } from 'sinon';
import getPostfix from '../src/getPostfix.js';

describe('getPostfix', function () {
Expand Down
1 change: 0 additions & 1 deletion ember-scoped-css/test/rewriteCss.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'chai';
import { stub } from 'sinon';
import rewriteCss from '../src/rewriteCss.js';

describe('rewriteCss', function () {
Expand Down
Loading