Giter Club home page Giter Club logo

bem-vscode-extension's Introduction

BEM Helper

A VSCode extension to help when using the BEM (Block-Element-Modifier) class naming convention in HTML.

Get it on the VSCode Marketplace.

Got any feedback, issues or feature requests? Send them my way via GitHub Issues.

Language Support

Currently, the languages that are officially supported are:

  • HTML
  • React (Jsx)
  • React (Tsx)
  • Razor (.net core / framework)
  • Vue
  • PHP

If there are any languages that you want support added for then please open a github issue

Commands

Command name Description Shortcut
bemHelper.insertBemElement Insert a new BEM element under the current block alt + b e
bemHelper.insertBemModifier Insert a new BEM modified element, copying the classname prefix of the previous element alt + b m
bemHelper.insertClassName Insert a BEM classname in the current cursor position alt + b c
bemHelper.generateStyleSheet Generate a new file containing CSS/LESS/SCSS for the current HTML file alt + b s
bemHelper.generateStyleSheetFromSelection Generate a new file containing CSS/LESS/SCSS for the current selected elements
bemHelper.convertSelectionToCase Convert the current text selection to a given case

Settings

Setting Description Allowed Values
bemHelper.classNameCase The allowed case styling of class names. Can be a single value or a list of values, separated by commas (e.g "kebab,snake") any, kebab, snake, camel, pascal, shoutingSnake
bemHelper.responsiveLinting Enable/disable linting checks whenever a file contents changes. Disable for increased performace. Reload window to take effect true, false
bemHelper.showDepthWarnings Enable/disable depth warnings. e.g block__block2__element true, false
bemHelper.elementSeparator The string to use as a separator for elements. By default is set to __. Reload window to take effect any string
bemHelper.modifierSeparator The string to use as a separator for modifiers. By default is set to --. Reload window to take effect any string
bemHelper.sortGeneratedStylesheets Controls whether generated stylesheets should be sorted alphabetically true, false
bemHelper.maxWarningsCount The maximum number of diagnostic warnings to show. Defaults to 100. number
bemHelper.ignoreClassNames A list of class names that should be ignored as parents (blocks) when inserting new elements or when generating a stylesheet. A list of strings
bemHelper.blockSelectionMode The method to use for selecting a parent block when inserting elements prefer-explicit, first-parent, explicit-only
bemHelper.newLineAfterInsert Should a newline be inserted after inserting an element? true, false

Generating LESS / SCSS / CSS

Generate stylesheets from your BEM markup using the generateStylesheet command. When using LESS or SCSS, the classnames will be appropriately nested and ready for you to start styling.

If you don't like fancy pre-processors, you can also generate plain CSS.

Generating a stylesheet from HTML

Inserting Elements

Both regular and modified element snippets can be inserted which already contain the parent class prefix. By default, these commands are bound to alt + b e (insertBemElement) and alt + b m (insertBemModifier), but they can be modified inside of the VSCode keyboard shortcuts menu.

Inserting a BEM child element

Diagnostic Help

BEM helper provides warnings when class names are in violation of BEM naming standards.

Classes not following BEM standards

Class name warnings

Classes not following the specified case

A quick fix is included to make fixing case name issues quicker.

You can specify your preferred casing in the extension settings using bemHelper.classNameCase.

Code quick fix for incorrect class name casing

bem-vscode-extension's People

Contributors

box-of-hats avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bem-vscode-extension's Issues

`alt + b e` don't work as expected in Vue.js

BEM Helper Version

0.7.0

Steps to reproduce

First I create a new file: index.html

...
  <div class="nav-bar" :class="{'is-hidden':isHidden}">
    //
  </div>
...

Then I press alt + b e to insert element.

What is Expected?

...
  <div class="nav-bar" :class="{'is-hidden':isHidden}">
    <div class="nav-bar__"></div>
  </div>
...

What is actually happening?

...
  <div class="nav-bar" :class="{'is-hidden':isHidden}">
    <div class="{__"></div>
  </div>
...

details

I rolled back to version 0.6.6 or changed the code like this and it works fine.

...
  <div :class="{'is-hidden':hidden}" class="nav-bar">
    //
  </div>
...

Thank you for making such a great plugin!

Incorrect recommendation with modifier name conventions

When naming the modifier of an element as follows: block__element_modifier_modifier-value, the extension says the name is wrong and prompts me to rename it like this: block__element-modifier-modifier-value (it "thinks" the modifier is name of an element).
Example:

<div class="links">
        <a class="links__projects links__projects_indent_right">Projects</a>
</div>

After this is written, the projects_indent_right gets highlighted as incorrect part and popup says this should be named as projects-indent-right which is incorrect modifier naming as said here

Use multiple classNameCases for block, element and modifier

There are projects which use a mixture of classNameCases, for example, the component's classname as PascalCase and the rest as kebab-case (see the scss style guide of the open source project "thenewboston").

This means, if I choose one classname case in the bemHelper options, that the linting shows me every class as a problem. If I use "any", it gives me no advise at all. Therefor, I would like to use a list which lets me choose which styles I want to use:

Instead of this:

  // The allowed case styling of class names.
  //  ...
  "bemHelper.classNameCase": "kebab",

I want this:

  "bemHelper.classNameCase": ["pascal", "kebab"],

or even a differentiation like this:

  "bemHelper.blockClassNameCase": "pascal",
  "bemHelper.elementClassNameCase": "kebab",
  "bemHelper.modifierClassNameCase": "kebab",

I suppose that not all combinations make sense. So it may also be okay, to use a predefined set of triples.

What do you think about this? 🙂

Review usage of workspaceContains activationEvent

Hi, I'm reaching out to let you know that we are fixing a bug with the workspaceContains VS Code extension activationEvent that could change the activation behavior for your extension.

Here's the issue: This event is supposed to start a search in the user's workspace with the given glob pattern, and activate the extension if it finds a match. A pattern like *.txt should find a file in the root of the workspace matching *.txt, but it should not search the entire workspace. A pattern like **/*.txt should recursively search the entire workspace. We discovered that VS Code is incorrectly applying the ** pattern to every workspaceContains pattern that includes a *.

Since this may impact the startup performance of VS Code, we need to scope these searches correctly. Once we fix this, a pattern like *.txt will only match a .txt file in the root of the workspace.

The change will be in VS Code Insiders in early January. It will be released with 1.53 in early February. Please see microsoft/vscode#110510 for more details and let me know if you have any questions.

shortcut for repeating name of element under a certain block

I have a block called 'header'. It has an element inside called 'main-logo'. The 'main-logo' has couple of child elements. So, for each of the child element, I need to manually type the element name 'main-logo' over and over again. So let me know is there any shortcut to avoid this repeating manual typing of 'main-logo' in each child element under 'main-logo' element. The code is as follows.

Bem Helper Shortcut Code:
.header>.-main-logo>.-main-logo-container>.-main-logo-link>.-main-logo-image|bem

Result:

		<div class="header__main-logo">
			<div class="header__main-logo-container">
				<div class="header__main-logo-link">
					<div class="header__main-logo-image"></div>
				</div>
			</div>
		</div>
	</div>```

Add "Generete class name" command

Sometimes I encouter the case when I already have an element but there is no class attribute on it - I think that's would be greate if I could generate a class name and then paste it.

Mac hot-keys

Hello!

Thank you for application.

I have a question.
How can i use hot-keys on mac?

When i push option+b e - vscode say me its not correct.

Possible improvement: Generate the classes in order of appearance in the HTML.

Hello, thank you for your excellent contribution.

I have a possible improvement proposal: Generate the classes in order of appearance in the HTML.

Currently it generates the classes but out of order, which in my opinion is better to read them in the order of appearance in the HTML, since it helps to have the file better organized. Currently what I do is order them manually. I attach a small example of what I am talking about.

Thanks for everything.

HTML
CSS

Support for custom element and modifier separators

I was wondering if it would be possible to add a setting to have custom element and modifier separators. Our templating engine doesn't respond well to having -- inside an HTML comment. When we go about commenting entire blocks of code with the normal BEM separators, we end up with errors. To make life easier for ourselves, we separate modifiers with a different separator. I wouldn't mind making my own PR if you don't have the time.

Add option to change quotes for class names

Hi, this is great extension!)

I have only two limitations when using it.

First - there is no support for React (JS) files. It creates elements with "class" instead of "className".

Secondly - there is no option to change double quotes to single for classNames. (Motivation - different companies have their own style guides)

It is possible to generate the code directly to the clipboard?

Sorry if you thought it was a problem, but didn't know where to put this question. Its complement is very good, but there are times when I want to generate my code in parts and generating a new file at all times becomes tiring. Thank you so much for everything.

Support for jsx (React)

it would be very nice for this extension to work with jsx (React) because everyone is using only new frameworks and would become more popular if it supports jsx (I do not think it's a big problem adding support for that)

allow _modifier-name

Thanks for plugin.
Version: 0.7.5

My settings of plugin looks like

{ "editor.largeFileOptimizations": false, "explorer.confirmDragAndDrop": false, "editor.minimap.enabled": true, "window.zoomLevel": 0, "explorer.confirmDelete": false, "terminal.integrated.shell.windows": "D:\\Program Files\\Git\\git-bash.exe", "terminal.external.windowsExec": "D:\\Program Files\\Git\\git-bash.exe", "git.enableSmartCommit": true, "git.confirmSync": false, **"bemHelper.modifierSeparator": "_"** }

and extansion setting looks like
2019-10-08_09-35-02.

By default BEM metodology uses _ as .modifierSepararor link. But if I configure the plugin as above, it does not work correctly, and emphasizes classes with modifier because it considers ` _ ' as part of the class name.
2019-10-08_09-39-44

_key-value separator in _modifiers

Hi, in BEM methodology, it is permissible to set _modifiers with an additional _key-value. For example:

block-name__element-name_modifier-name_modifier-value

Read more

Unfortunately, now the extantion handles such classes as an error. Although _ is set as the modifier separator, it is suggested to use kebab case instead of _ when using _key-value.

2019-10-12_14-18-16

It would be super cool if you added a rule to the plugin settings to separate modifiers and modifier values, according to the BEM naming convention. And also improved handling of key-value modifiers.

Thanks a lot.

Eager document validation slows down other extensions

👋 Hey. VS Code Team here.

This extension appeared as causing slow-downs of the extension host and thereby also other extensions. See microsoft/vscode#155520 (comment) for the related discussion on our end.

I took a quick glance and I believe this is due to "responsiveLinting" - it is too eager as it validates documents as you type without any kind of debouncing. See https://github.dev/Box-Of-Hats/Bem-VSCode-Extension/blob/4918250dbfc60a37e33ddb6f3f0bfd047bad737f/src/extension.ts#L72. Doing an expensive operation on such a high frequency event is discouraged and validation should be debounced/delayed by something like 500ms

Templating support

Is there support for html like templating like twig, smarty, handlebars ...

Modify generated scss/css/less code

Hey,

Thank you for developing this extension.

I have a question - is there a way to modify the output of generated SCSS? I'd like to add to it some extra default lines that I'm using frequently.

Cheers,
Furai

class="undefined__" is inserted when there is no elements to inherit from

image

It might be the desired behavior, but I'd propose to insert either something more meaningful, e.g. current file name in user specified case (`in `bemHelper.classNameCase`), or even empty class name. Moreover, in current version you need two `ctrl + backspace` presses to get rid of the inserted class - it would be definitely better to select the whole class name in this case. @Box-Of-Hats WDYT?

Possible new option: Skip some classes entirely.

Hello, thank you for your contribution to the community.

I want to propose the addition of a characteristic: allow to specify in the configuration which classes should be completely omitted.

For example, sometimes some css classes are used from frameworks like Bootstrap that you want to skip completely, in any case it can be removed manually, but it can take your time in a large project, with many components.

Thanks for everything.
Config BEM

How do shortcut keys specify labels?

example:

<view class="list">
  <div class="list__"></div>  //Use alt + b e shortcut generated here
 </view>

Expectation:

<view class="list">
  <view  class="list__"></view >  //This is the result I expected
 </view>

Generate CSS selectors from current selection in HTML files

I would really appreciate if I could generate CSS selectors from just current selection in HTML file as in opposite to generating CSS selectors for whole HTML file.
I find myself building stuff gradually and I often add new BEM components to existing HTML files. Extracting only newly added selectors / components from generated stylesheet is little inconvenient. But still 100x more convenient then writing them "manually" like I did before 👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.