All Projects β†’ hudochenkov β†’ Postcss Sorting

hudochenkov / Postcss Sorting

Licence: mit
PostCSS plugin to keep rules and at-rules content in order.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Postcss Sorting

humanize
A collection of utility functions, with built-in localization, for humanizing various types of data input
Stars: ✭ 73 (-83.33%)
Mutual labels:  formatting
Wasabi
🍣 A lightweight console printing and formatting toolkit
Stars: ✭ 272 (-37.9%)
Mutual labels:  formatting
Markdeep
Official public Markdeep source archive
Stars: ✭ 373 (-14.84%)
Mutual labels:  formatting
sublime-php-grammar
An smart macro PHP plugin for Sublime Text.
Stars: ✭ 30 (-93.15%)
Mutual labels:  formatting
Address Formatting
templates to format geographic addresses
Stars: ✭ 253 (-42.24%)
Mutual labels:  formatting
Csconsoleformat
.NET C# library for advanced formatting of console output [Apache]
Stars: ✭ 296 (-32.42%)
Mutual labels:  formatting
postcss-copy
An async postcss plugin to copy all assets referenced in CSS files to a custom destination folder and updating the URLs.
Stars: ✭ 39 (-91.1%)
Mutual labels:  postcss-plugins
Better Comments
Stars: ✭ 420 (-4.11%)
Mutual labels:  formatting
Vue Cleave Component
Vue.js component for Cleave.js ⌨️
Stars: ✭ 271 (-38.13%)
Mutual labels:  formatting
React Element To Jsx String
Turn a ReactElement into the corresponding JSX string
Stars: ✭ 349 (-20.32%)
Mutual labels:  formatting
kirai
String formatting library for Java, Android, Web and Unix Terminal
Stars: ✭ 69 (-84.25%)
Mutual labels:  formatting
format.nvim
Neovim lua plugin to format the current buffer with external executables
Stars: ✭ 189 (-56.85%)
Mutual labels:  formatting
Bullet
πŸš… Interactive prompts made simple. Build a prompt like stacking blocks.
Stars: ✭ 3,257 (+643.61%)
Mutual labels:  formatting
formatting
源码格式θ‡ͺεŠ¨εŒ–θ°ƒζ•΄ε·₯ε…·
Stars: ✭ 37 (-91.55%)
Mutual labels:  formatting
Autoprefixer
Parse CSS and add vendor prefixes to rules by Can I Use
Stars: ✭ 20,001 (+4466.44%)
Mutual labels:  postcss-plugins
pypandoc
Thin wrapper for "pandoc" (MIT)
Stars: ✭ 510 (+16.44%)
Mutual labels:  formatting
Postcss Utilities
PostCSS plugin to add a collection of mixins, shortcuts, helpers and tools for your CSS
Stars: ✭ 293 (-33.11%)
Mutual labels:  postcss-plugins
Phonenumberkit
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
Stars: ✭ 4,362 (+895.89%)
Mutual labels:  formatting
Ascii Tables
Quickly format table in ASCII. Great for code comments, or Github Markdown!
Stars: ✭ 416 (-5.02%)
Mutual labels:  formatting
Decoro
Android library designed for automatic formatting of text input by custom rules
Stars: ✭ 325 (-25.8%)
Mutual labels:  formatting

PostCSS Sorting

npm version npm downloads last month

PostCSS plugin to keep rules and at-rules content in order.

Also available as Sublime Text, Atom, VS Code, and Emacs plugin.

Lint and autofix style sheets order with stylelint-order.

Features

  • Sorts rules and at-rules content.
  • Sorts properties.
  • Sorts at-rules by different options.
  • Groups properties, custom properties, dollar variables, nested rules, nested at-rules.
  • Supports CSS, SCSS (using postcss-scss), HTML (with postcss-html), CSS-in-JS (with postcss-jsx), PreCSS and most likely any other syntax added by other PostCSS plugins.

Installation

$ npm install --save-dev postcss postcss-sorting

Options

The plugin has no default options. Everything is disabled by default.

  • order: Specify the order of content within declaration blocks.
  • properties-order: Specify the order of properties within declaration blocks.
  • unspecified-properties-position: Specify position for properties not specified in properties-order.
  • throw-validate-errors: Throw config validation errors instead of showing and ignoring them. Defaults to false.

Caveats

Handling comments

Comments that are before node and on a separate line linked to that node. Shared-line comments are also linked to that node. Shared-line comments are comments which are located after a node and on the same line as a node.

a {
	top: 5px; /* shared-line comment belongs to `top` */
	/* comment belongs to `bottom` */
	/* comment belongs to `bottom` */
	bottom: 15px; /* shared-line comment belongs to `bottom` */
}

Ignored at-rules

Some at-rules, like control and function directives in Sass, are ignored. It means rules won't touch content inside these at-rules, as doing so could change or break functionality.

CSS-in-JS

Plugin will ignore rules, which have template literal interpolation, to avoid breaking logic:

const Component = styled.div`
	/* The following properties WILL NOT be sorted, because interpolation is on properties level */
	z-index: 1;
	top: 1px;
	${props => props.great && 'color: red'};
	position: absolute;
	display: block;

	div {
		/* The following properties WILL be sorted, because interpolation for property value only */
		z-index: 2;
		position: static;
		top: ${2 + 10}px;
		display: inline-block;
	}
`;

Migration from 2.x

Remove all *-empty-line-before and clean-empty-lines options. Use stylelint with --fix option instead.

properties-order doesn't support property groups. Convert it to a simple array. Use stylelint-order with --fix option for empty line before property groups.

Config for 2.x:

{
	"properties-order": [
		{
			"properties": [
				"margin",
				"padding"
			]
		},
		{
			"emptyLineBefore": true,
			"properties": [
				"border",
				"background"
			]
		}
	]
}

Config for 3.x:

{
	"properties-order": [
		"margin",
		"padding",
		"border",
		"background"
	]
}

Usage

See PostCSS docs for examples for your environment.

Text editor

This plugin available as Sublime Text, Atom, VS Code, and Emacs plugin.

Gulp

Add Gulp PostCSS and PostCSS Sorting to your build tool:

npm install gulp-postcss postcss-sorting --save-dev

Enable PostCSS Sorting within your Gulpfile:

var postcss = require('gulp-postcss');
var sorting = require('postcss-sorting');

gulp.task('css', function () {
	return gulp.src('./css/src/*.css').pipe(
		postcss([
			sorting({ /* options */ })
		])
	).pipe(
		gulp.dest('./css/src')
	);
});

Grunt

Add Grunt PostCSS and PostCSS Sorting to your build tool:

npm install grunt-postcss postcss-sorting --save-dev

Enable PostCSS Sorting within your Gruntfile:

grunt.loadNpmTasks('grunt-postcss');

grunt.initConfig({
	postcss: {
		options: {
			processors: [
				require('postcss-sorting')({ /* options */ })
			]
		},
		dist: {
			src: 'css/*.css'
		}
	}
});

Command Line

Add postcss-cli and PostCSS Sorting to your project:

npm install postcss-cli postcss-sorting --save-dev

Create an appropriate postcss.config.js like this example:

module.exports = (ctx) => ({
  plugins: {
    'postcss-sorting': {
      'order': [
        'custom-properties',
        'dollar-variables',
        'declarations',
        'at-rules',
        'rules'
      ],

      'properties-order': 'alphabetical',

      'unspecified-properties-position': 'bottom'
    }
  }
})

Or, add the 'postcss-sorting' section to your existing postcss-cli configuration file. Next, execute:

postcss -c postcss.config.js  --no-map -r your_css_file.css

For more information and options, please consult the postcss-cli docs.

Related tools

stylelint and stylelint-order help lint style sheets and let you know if style sheet order is correct. Also, they could autofix style sheets.

I recommend Prettier for formatting style sheets.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].