File tree 6 files changed +207
-0
lines changed
6 files changed +207
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Rules loading script library
3
+ * @author kazuya kawaguchi (a.k.a. kazupon)
4
+ * Forked by https://github.com/mysticatea/eslint-plugin-eslint-comments/tree/master/scripts/lib/rules.js
5
+ */
6
+ 'use strict'
7
+
8
+ const { readdirSync } = require ( 'fs' )
9
+ const { resolve, basename } = require ( 'path' )
10
+
11
+ const rules = readdirSync ( resolve ( __dirname , '../../lib/rules' ) )
12
+ . map ( fileName => basename ( fileName , '.js' ) )
13
+ . map ( name => {
14
+ const meta = require ( `../../lib/rules/${ name } ` ) . meta
15
+ return {
16
+ id : `vue-i18n/${ name } ` ,
17
+ name,
18
+ category : String ( meta . docs . category ) ,
19
+ description : String ( meta . docs . description ) ,
20
+ recommended : Boolean ( meta . docs . recommended ) ,
21
+ fixable : Boolean ( meta . fixable ) ,
22
+ deprecated : Boolean ( meta . deprecated ) ,
23
+ replacedBy : meta . docs . replacedBy || null
24
+ }
25
+ } )
26
+
27
+ module . exports = rules
28
+ module . exports . withCategories = [
29
+ 'Best Practices' ,
30
+ 'Stylistic Issues'
31
+ ] . map (
32
+ category => ( {
33
+ category,
34
+ rules : rules . filter (
35
+ rule => rule . category === category && ! rule . deprecated
36
+ )
37
+ } )
38
+ )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Utility script library
3
+ * @author kazuya kawaguchi (a.k.a. kazupon)
4
+ * Forked by https://github.com/mysticatea/eslint-plugin-eslint-comments/tree/master/scripts/lib/utils.js
5
+ */
6
+ 'use strict'
7
+
8
+ const { readdirSync } = require ( 'fs' )
9
+ const { basename } = require ( 'path' )
10
+ const { CLIEngine } = require ( 'eslint' )
11
+ const linter = new CLIEngine ( { fix : true } )
12
+
13
+ function format ( text ) {
14
+ const lintResult = linter . executeOnText ( text )
15
+ return lintResult . results [ 0 ] . output || text
16
+ }
17
+
18
+ function createIndex ( dirPath ) {
19
+ const dirName = basename ( dirPath )
20
+ return format ( `/** DON'T EDIT THIS FILE; was created by scripts. */
21
+ 'use strict'
22
+
23
+ module.exports = {
24
+ ${ readdirSync ( dirPath )
25
+ . map ( file => basename ( file , '.js' ) )
26
+ . map ( id => `'${ id } ': require('./${ dirName } /${ id } '),` )
27
+ . join ( '\n ' ) }
28
+ }
29
+ ` )
30
+ }
31
+
32
+ module . exports = {
33
+ createIndex,
34
+ format
35
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Update docs headers script
3
+ * @author kazuya kawaguchi (a.k.a. kazupon)
4
+ * Forked by https://github.com/mysticatea/eslint-plugin-eslint-comments/tree/master/scripts/update-docs-headers.js
5
+ */
6
+ 'use strict'
7
+
8
+ const { writeFileSync, readFileSync } = require ( 'fs' )
9
+ const { join } = require ( 'path' )
10
+ const rules = require ( './lib/rules' )
11
+ const PLACE_HOLDER = / ^ # [ ^ \n ] * \n + > .+ \n + (?: - .+ \n ) * \n * / u
12
+
13
+ for ( const rule of rules ) {
14
+ const filePath = join ( __dirname , `../docs/rules/${ rule . name } .md` )
15
+ const headerLines = [ `# ${ rule . id } ` , '' , `> ${ rule . description } ` ]
16
+
17
+ if ( rule . recommended || rule . deprecated || rule . fixable ) {
18
+ headerLines . push ( '' )
19
+ }
20
+
21
+ if ( rule . deprecated ) {
22
+ headerLines . push (
23
+ `- :warning:️ This rule was **deprecated** and replaced by ${ rule . replacedBy
24
+ . map ( id => `[${ id } ](${ id } .md) rule` )
25
+ . join ( ', ' ) } .`
26
+ )
27
+ } else if ( rule . recommended ) {
28
+ headerLines . push (
29
+ '- :star: The `"extends": "plugin:vue-i18n/recommended"` property in a configuration file enables this rule.'
30
+ )
31
+ }
32
+
33
+ if ( rule . fixable ) {
34
+ headerLines . push (
35
+ '- :black_nib:️ The `--fix` option on the [command line](http://eslint.org/docs/user-guide/command-line-interface#fix) can automatically fix some of the problems reported by this rule.'
36
+ )
37
+ }
38
+ headerLines . push ( '' , '' )
39
+
40
+ writeFileSync (
41
+ filePath ,
42
+ readFileSync ( filePath , 'utf8' )
43
+ . replace ( PLACE_HOLDER , headerLines . join ( '\n' ) )
44
+ )
45
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Update docs index script
3
+ * @author kazuya kawaguchi (a.k.a. kazupon)
4
+ * Forked by https://github.com/mysticatea/eslint-plugin-eslint-comments/tree/master/scripts/update-docs-index.js
5
+ */
6
+ 'use strict'
7
+
8
+ const { writeFileSync } = require ( 'fs' )
9
+ const { resolve } = require ( 'path' )
10
+ const { withCategories } = require ( './lib/rules' )
11
+
12
+ function toTableRow ( rule ) {
13
+ const mark = `${ rule . recommended ? '🌟' : '' } ${ rule . fixable ? '✒️' : '' } `
14
+ const link = `[vue-i18n/<wbr>${ rule . name } ](./${ rule . name } .html)`
15
+ const description = rule . description || '(no description)'
16
+ return `| ${ link } | ${ description } | ${ mark } |`
17
+ }
18
+
19
+ function toCategorySection ( { category, rules } ) {
20
+ return `## ${ category }
21
+
22
+ | Rule ID | Description | |
23
+ |:--------|:------------|:---|
24
+ ${ rules . map ( toTableRow ) . join ( '\n' ) }
25
+ `
26
+ }
27
+
28
+ writeFileSync (
29
+ resolve ( __dirname , '../docs/rules/README.md' ) , `# Available Rules
30
+
31
+ - :star: mark: the rule which is enabled by \`vue-i18n/recommended\` preset.
32
+ - :black_nib: mark: the rule which is fixable by \`eslint --fix\` command.
33
+
34
+ ${ withCategories . map ( toCategorySection ) . join ( '\n' ) }
35
+ `
36
+ )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Update recommended rules
3
+ * @author kazuya kawaguchi (a.k.a. kazupon)
4
+ * Forked by https://github.com/mysticatea/eslint-plugin-eslint-comments/tree/master/scripts/update-recommended-rules.js
5
+ */
6
+ 'use stricut'
7
+
8
+ const { writeFileSync } = require ( 'fs' )
9
+ const { resolve } = require ( 'path' )
10
+ const rules = require ( './lib/rules' )
11
+ const { format } = require ( './lib/utils' )
12
+
13
+ // recommended.js
14
+ writeFileSync (
15
+ resolve ( __dirname , '../lib/configs/recommended.js' ) ,
16
+ format ( `/** DON'T EDIT THIS FILE; was created by scripts. */
17
+ 'use strict'
18
+
19
+ module.exports = {
20
+ plugins: ['vue-i18n'],
21
+ rules: {
22
+ ${ rules . filter ( rule => rule . recommended )
23
+ . map ( rule => `'${ rule . id } ': 'error',` )
24
+ . join ( '\n ' ) }
25
+ },
26
+ }` )
27
+ )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @fileoverview Update script
3
+ * @author kazuya kawaguchi (a.k.a. kazupon)
4
+ * Forked by https://github.com/mysticatea/eslint-plugin-eslint-comments/tree/master/scripts/update.js
5
+ */
6
+ 'use stricut'
7
+
8
+ const { writeFileSync } = require ( 'fs' )
9
+ const { resolve } = require ( 'path' )
10
+ const { createIndex } = require ( './lib/utils' )
11
+
12
+ // docs.
13
+ require ( './update-docs-headers' )
14
+ require ( './update-docs-index' )
15
+
16
+ // recommended rules.
17
+ require ( './update-recommended-rules' )
18
+
19
+ // indices.
20
+ for ( const dirPath of [
21
+ resolve ( __dirname , '../lib/configs' ) ,
22
+ resolve ( __dirname , '../lib/rules' ) ,
23
+ resolve ( __dirname , '../lib/utils' )
24
+ ] ) {
25
+ writeFileSync ( `${ dirPath } .js` , createIndex ( dirPath ) )
26
+ }
You can’t perform that action at this time.
0 commit comments