UNPKG

1.35 kBJavaScriptView Raw
1/**
2 * Requires `'use strict';` statements
3 *
4 * Values:
5 * - `true` for default behavior (require 'use strict' statements for files)
6 *
7 * #### Example
8 *
9 * ```js
10 * "requireUseStrict": true
11 * ```
12 *
13 * ##### Valid
14 *
15 * ```js
16 * 'use strict';
17 * // code
18 * ```
19 *
20 * ```js
21 * // comment line or block
22 * 'use strict';
23 * // code
24 * ```
25 *
26 * ```js
27 * // comment line or block
28 *
29 * 'use strict';
30 * // code
31 * ```
32 *
33 * ##### Invalid
34 *
35 * ```js
36 * // code
37 * ```
38 */
39
40var assert = require('assert');
41
42module.exports = function() {};
43
44module.exports.prototype = {
45
46 configure: function(options) {
47 if (typeof options !== 'object') {
48 assert(
49 options === true,
50 this.getOptionName() + ' option requires either a true value or an object'
51 );
52
53 var _options = {files: true};
54 return this.configure(_options);
55 }
56
57 this._checkFiles = (options.files === true);
58 },
59
60 getOptionName: function() {
61 return 'requireUseStrict';
62 },
63
64 check: function(file, errors) {
65 var program = file.getProgram();
66 var directive = program.directives[0];
67
68 if (directive) {
69 return;
70 }
71
72 errors.add(
73 '`"use strict";` is required at the top of each file',
74 program
75 );
76 }
77};